Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: Replace with returned results in svy loop
From
Richard Williams <[email protected]>
To
[email protected], [email protected]
Subject
Re: st: Replace with returned results in svy loop
Date
Sun, 29 May 2011 19:11:52 -0500
If in doubt where a value is stored, type -ereturn list- after the
estimation command. After -mean-, e(b) has the mean of the variable.
So, to get the mean stored in a scalar, do something like
webuse nhanes2f, clear
svy: mean houssiz
mat varmean = e(b)
scalar vmean = varmean[1,1]
Having said that, substituting the mean for missing data is generally
not considered the best practice in the world. And, there may be
other errors in your code (e.g. the == in the replace command looks
wrong) but I imagine those will become obvious once you tidy other things up.
At 03:11 PM 5/29/2011, Kate Schneider wrote:
Hello,
Sorr to bug everyone on a holiday weekend, but we're a graduate
student research group at the University of Washington working with a
large household survey dataset and have come up against some trouble.
We're trying to replace missing values of a variable with the results
of some other operation we've just performed (basically, a mean).
Right now, we're having trouble with the replace component of the
below operation. Does anyone know how torecall the previous command's
results from the svy calculation and use that data to replace missing
in a loop? Is this possible with survey data?
foreach X of varlist $fooditemall {
quietly count if `X'==1 & priceperkilo !=.
if `r(N)'>0 {
display "Variable is: " "`X'"
svy, subpop(`X'): mean priceperkilo
}
quietly count if `X'==1 & priceperkilo ==.
if `r(N)'>0 {
replace priceperkilo == e(????) if `X'==1 & priceperkilo ==.
}
}
Thanks for your insight! If you need more information please let me know.
Kate
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/
-------------------------------------------
Richard Williams, Notre Dame Dept of Sociology
OFFICE: (574)631-6668, (574)631-6463
HOME: (574)289-5227
EMAIL: [email protected]
WWW: http://www.nd.edu/~rwilliam
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/