Any help would be very much appreciated. I have panel data - ids of each individual in one column, years in the next column, and variables in each following column. The variables are how many books they read and how many hours of TV they watched, by year.
I would like to generate the mean, and standard deviations for these variables, between 2005 and 2010.
foreach var of varlist booksread tvwatched {
bysort id: egen `var'_mean2005to2010=mean(`var') if (year>=2005 & year<=2010)
drop `var'_mean2005to2010 if !(year>=2005 & year<=2010)
}
This loops once, generates the booksread and then does not work for tvwatched. Instead I get 'invalid syntax r(198)', after the booksread has been generated. I can't figure out why it works only for the first pass. Help would be hugely appreciated
p.s. this is a very much simplified example, I have 50 variables (hence why I'm not doing it manually), but it still doesn't work even when reduced to 2.
I would like to generate the mean, and standard deviations for these variables, between 2005 and 2010.
foreach var of varlist booksread tvwatched {
bysort id: egen `var'_mean2005to2010=mean(`var') if (year>=2005 & year<=2010)
drop `var'_mean2005to2010 if !(year>=2005 & year<=2010)
}
This loops once, generates the booksread and then does not work for tvwatched. Instead I get 'invalid syntax r(198)', after the booksread has been generated. I can't figure out why it works only for the first pass. Help would be hugely appreciated
p.s. this is a very much simplified example, I have 50 variables (hence why I'm not doing it manually), but it still doesn't work even when reduced to 2.
Comment