Hi STATA-list members,
I am trying to run a large number of summary statistics (means) and input them into a matrix using Stata 13.0. For the first part of this process, I’m looping through two of my variables (age and birthyear) and storing the means into a vector. It works very well with the “summ” command since not every age/birthyear combination have an observation, and the scalar output from “summ” stores missings.
The problem occurs when I run a second set using sampling weights. Since most convenient commands like tabstat/tabout/summ don’t work with “svy”, I am using the “mean” command. Now I get a warning “no observations” for some age/year combinations and it stops the loop. When I use the “cap” option, it continues but then stores the incorrect vector (e(b)) from whatever was the last non-missing output.
Here is the code I am using:
forval i=15/25 { // age
forval j=1988/2000 { // birthyear
cap mean inschool if age==`i' & birthyear==`j' [pweight=iweight]
mat school_`i'_`j'= e(b)
}
}
I would be grateful for any advice on how to correctly automate this. Thank you!
Best,
Crystal
I am trying to run a large number of summary statistics (means) and input them into a matrix using Stata 13.0. For the first part of this process, I’m looping through two of my variables (age and birthyear) and storing the means into a vector. It works very well with the “summ” command since not every age/birthyear combination have an observation, and the scalar output from “summ” stores missings.
The problem occurs when I run a second set using sampling weights. Since most convenient commands like tabstat/tabout/summ don’t work with “svy”, I am using the “mean” command. Now I get a warning “no observations” for some age/year combinations and it stops the loop. When I use the “cap” option, it continues but then stores the incorrect vector (e(b)) from whatever was the last non-missing output.
Here is the code I am using:
forval i=15/25 { // age
forval j=1988/2000 { // birthyear
cap mean inschool if age==`i' & birthyear==`j' [pweight=iweight]
mat school_`i'_`j'= e(b)
}
}
I would be grateful for any advice on how to correctly automate this. Thank you!
Best,
Crystal
Comment