Taking the Grunfeld data, which is built-in in R, for example,
(1)How can I construct a dataset (or dataframe) that consists of the data
of all firms in 1951?
(2)How can I calculate the average capital in each form over the period
1951-1954?
What I can imagine is to categorize the data by firm,
Hi,
1)
Grunfeld1951-Grunfeld[Grunfeld$year==1951,]
Grunfeld1951
# firm year inv value capital
#17 1 1951 755.90 4833.00 1207.70
#37 2 1951 588.20 2289.50 342.10
#57 3 1951 135.20 1819.40 671.30
#77 4 1951 160.62 809.00 203.50
#97 5 1951 80.30 327.30 683.90
#117
Hi,
Just to add:
load:
library(plyr) #forgot
if you are using ddply()
#you can directly use subset() in aggregate()
aggregate(capital~firm,data=subset(Grunfeld,year%in% 1951:1954),mean)
# firm capital
#1 1 1660.4500
#2 2 519.9000
#3 3 771.6500
#4 4 313.7750
#5 5
3 matches
Mail list logo