I have had so many requests for this code that I am posting it instead of
emailing individually, although i would love to discuss with anyone
interested- please feel free to email me. I am a nutrition epidemiology
student, and this program was written to obtain estimates of within and
between person variance in 2 days of diet intake. The dataset consists of 2
obs/individual for all nutrients (energy, protein, etc), along with
demographic variables gender, age, pov, and urban/rural residence.
below find a .do file, and under it an .ado file.
these file run multiple models, one for each nutrient, and outputs a dataset
of results for each one. the iweight is the only weight specification
allowed when using the mle estimator, so we took the pweights and adjusted
them. we used the mle estimator to compare to SAS results, but the re
estimator would work too. the point estimates were almost identical to SAS
proc mixed.
regards,
lisa jahns
** yourfilename.do **
** this .do is a macro that calls in the .ado file (the xtreg equation) and
bootstraps the results 200 times **
capture log close
set more off
log using your_log_name, replace text
program drop _all
drop _all
set memory 30m
use your_data, clear
run your_xtreg.ado
log close
#delimit ;
for varlist kjnrgy energy protein tfat carbo pct_pro pct_fat pct_cho
calcium iron magnes thiamin ribo niacin vitc:
set seed 1234567
\ log using your_variable_ log_X.txt, replace text
\ bstrap your_xtreg_ado, cluster(svy_strat svy_psu) reps(200) args(X) d
saving(your_variable_ log_X) replace every(1)
\ log close;
#delimit cr
end
** your_xtreg.ado**
capture program drop svy_re
program define svy_re
version 7.0
if "`1'" =="?" {
# delimit ;
global S_1 " gender age pov urbrur within between rho ymean
ratio";
#delimit cr
exit
}
xtreg `2' gender age pov urbrur [iw=weight], i(id) mle
local gender = _b[gender]
local age = _b[age]
local pov = _b[pov]
local urbrur = _b[urbrur]
local within = e(sigma_e)
local between = e(sigma_u)
local ratio =(e(sigma_e)/e(sigma_u))
local rho = e(rho)
sum `2', meanonly
local ymean = r(mean)
post `1' (`gender') (`age') (`pov') (`urbrur') (`within') (`between')
(`rho') (`ymean') (`ratio')
end
>
>
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]]On Behalf Of Lisa Jahns
> Sent: Thursday, January 16, 2003 9:15 AM
> To: [email protected]
> Subject: st: Re: Survey regression with multi-level models
>
> James,
> We ran what is essentially a mixed effects model using xtreg, mle, then
> bootstrapped the results by stratum and psu level. email me if you would
> like the
> code to do this.
>
> lisa jahns
> Division of Nutritional epidemiology
> University of North Carolina
>
> Date: Mon, 30 Dec 2002 06:53:49 -0700
> From: "C.Shaw" <[email protected]>
> Subject: st: Survey regression with multi-level models
>
> Dear Statalisters,
>
> I have a multi-level dataset for which I believe a random effects or
> random coefficients model would be appropriate. However, the data were
> collected from a probability sample, and I would like to account for
> this in the estimation process. Does anyone know if there is a "svy"
> regression equivalent of -xtreg- or -xtgee- in Stata? I understand that
> the population-averaged model allows for pweights, but I do not believe
> that it allows for clustering or stratification. Any guidance would be
> greatly appreciated.
>
> - --
> James Shaw
> Graduate Research Associciate
> The University of Arizona
> P.O. Box 210207
> Tucson, AZ 85721
>
> *
> * For searches and help try:
> * http://www.stata.com/support/faqs/res/findit.html
> * http://www.stata.com/support/statalist/faq
> * http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/