Hello,
I am trying to create a new dataset from an output using postfile command. Specifically, I want to create variables cat1_ave as the mean of cat1, cat2_ave as the mean of cat2, until cat10_ave. I can successfully create the first two columns (i.e., year and cat1_ave). However, the remaining columns do not work. They are still the average of the cat1. I wondered how to solve this problem? I cannot figure it out. Below is my syntax.
capture postutil clear
postfile ms_year1 year cat1_ave cat2_ave cat3_ave ///
cat4_ave cat5_ave cat6_ave ///
cat7_ave cat8_ave cat9_ave cat10_ave ///
using ms_year1.dta, replace
forvalues yr = 2010/2017 {
sum cat1-cat10 if (year==`yr' & it=="ms")
local var "`k'"
post ms_year1 (`yr') (`r(mean)') (`r(mean)') (`r(mean)') ///
(`r(mean)') (`r(mean)') (`r(mean)') (`r(mean)') (`r(mean)') (`r(mean)') (`r(mean)')
}
postclose ms_year1
Many thanks,
David
I am trying to create a new dataset from an output using postfile command. Specifically, I want to create variables cat1_ave as the mean of cat1, cat2_ave as the mean of cat2, until cat10_ave. I can successfully create the first two columns (i.e., year and cat1_ave). However, the remaining columns do not work. They are still the average of the cat1. I wondered how to solve this problem? I cannot figure it out. Below is my syntax.
capture postutil clear
postfile ms_year1 year cat1_ave cat2_ave cat3_ave ///
cat4_ave cat5_ave cat6_ave ///
cat7_ave cat8_ave cat9_ave cat10_ave ///
using ms_year1.dta, replace
forvalues yr = 2010/2017 {
sum cat1-cat10 if (year==`yr' & it=="ms")
local var "`k'"
post ms_year1 (`yr') (`r(mean)') (`r(mean)') (`r(mean)') ///
(`r(mean)') (`r(mean)') (`r(mean)') (`r(mean)') (`r(mean)') (`r(mean)') (`r(mean)')
}
postclose ms_year1
Many thanks,
David
Comment