I am trying to get survey means for some demographic variables based on three groups: incar == 0, incar == 1, and both together (aka non-missings). In my actual code, it looks something like this after -svyset-
This lets me produce a nice little table with esttab (from SSC). However, the problem I'm running into is that it seems like the means are slightly different when I run them all together as part of a local, compared to if I ran them individually. The sample sizes are slightly different as well, with lower sample sizes when I run the local.
I assume this is because of something happening with the local? Does it only run for all non-missing observations in the local, or something like that? And I guess the obvious main question is if there's a way to avoid this?
I tried to recreate the problem with a publicly available dataset but wasn't able to (maybe the missings in loglead aren't distributed in a way that throws it off?)...here's the start of my code to do that if it's useful:
Code:
local demog age gender white svy: mean `demog' if incar != . estat sd estadd mat sd = r(sd) eststo svy: mean `demog' if incar == 0 estat sd estadd mat sd = r(sd) eststo svy: mean `demog' if incar == 1 estat sd estadd mat sd = r(sd) eststo
I assume this is because of something happening with the local? Does it only run for all non-missing observations in the local, or something like that? And I guess the obvious main question is if there's a way to avoid this?
I tried to recreate the problem with a publicly available dataset but wasn't able to (maybe the missings in loglead aren't distributed in a way that throws it off?)...here's the start of my code to do that if it's useful:
Code:
clear webuse nhanes2f svyset psuid [pweight=finalwgt], strata(stratid) svy: mean age if loglead != . local example sex age height weight svy: mean `example' if loglead != .
Comment