Hello all,
Here's an example code that reflects what my data looks like:
I am trying to generate 2 copies of all of my variables with foreach like this:
When I run this, I get error message invalid syntax r(198);
The idea is to then collapse the variables like this:
How can I resolve the error message above? Or is there a smarter way to go about this to end up with the mean, standard error, and standard deviation of each variable per year?
Many thanks in advance!
Here's an example code that reflects what my data looks like:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input byte(v1 v2) float v3 int year 1 1 1 2000 2 2 2 2000 3 3 3 2001 4 4 4 2001 end
Code:
foreach var of varlist_all {
gen `var[sd]' = `var'
gen `var[se]'= `var'
}
The idea is to then collapse the variables like this:
Code:
collapse (mean) v1 v2 v3 (semean) v1se v2se v3se (sd) v1sd v2sd v3sd , by (year)
Many thanks in advance!

Comment