I have big data set and i am trying to do some calculations. I want to produce some calculations based on the row sum based on the same date with different IDs and store their value.
ex for data set:-
gvkey(Id) date a b
0001 1/1/2000 15624000 10011531920
0001 2/1/2000 18480000 10592724720
0001 3/1/2000 16968000 10160611743
0002 1/1/2000 9375333997 10011531920
0002 2/1/2000 9943536057 10592724720
0002 3/1/2000 9470034340 10160611743
0003 1/1/2000 441665123.3 10011531920
0003 2/1/2000 412041243.1 10592724720
0003 3/1/2000 417427403.1 10160611743
I am trying to do this code but values are coming constantly same for me.
library(readxl)
library(tidyverse)
library(plyr)
df<-NewData
head(NewData)
a<-NewData %>%
mutate(firmMarket=NewData$cshoc*NewData$prccd)
head(a)
c<-ddply(b,.(gvkey,datadate),summarize,TotalMarket=sum(firmMarket))
Kindly help will be appreciated. Thanks in advance.