Lena Lindahl <[email protected]> asks how to bootstrap the standard
errors for the intraclass correlation after -xtmixed-:
> I want to estimate the correlation in income among pupils who went in the same
> school. In order to achieve the variance components needed to calculate the
> correlation I have used xtmixed in the following way:
>
> xtmixed income || school:, cov(unstructured) variance
>
> Then I get estimates of within and between school variance and their standard
> errors. The correlation is calculated as the proportion of the total variance
> that occurs between schools: ((between variance/(between+within variance)).
> How do I bootstrap standard errors of the correlation?
Lena can use -nlcom- after -xtmixed- to obtain the standard error for the
intraclass correlation. Here is an example using the auto dataset:
/***** begin example *****/
sysuse auto, clear
xtmixed mpg || rep78:
matrix list e(b)
local var_u exp([lns1_1_1]_b[_cons])^2
local var_e exp([lnsig_e]_b[_cons])^2
nlcom `var_u'/(`var_u'+`var_e')
mat V = r(V)
di as txt "SE = " as res sqrt(V[1,1])
/****** end example ******/
We can look up the corresponding names of the coefficients to be used in
-nlcom- from the column names of the e(b) matrix (. matrix list e(b)). Also,
since the coefficients in e(b) are stored in the alternative metric we need to
transform them first to get the variance components. Note also that since the
dimension of the random effect is one in the model above there is no need to
specify -cov(unstructured)-.
To bootstrap standard error of the intraclass correlation Lena needs to write
a separate program that returns the values of this standard error in r() and
use that program in -bootstrap-:
/***** begin example *****/
cap program drop bs_rho_se
program bs_rho_se, rclass
xtmixed mpg || rep78:
local var_u exp([lns1_1_1]_b[_cons])^2
local var_e exp([lnsig_e]_b[_cons])^2
nlcom `var_u'/(`var_u'+`var_e')
ret list
tempname V
mat `V' = r(V)
return scalar rho_se = sqrt(`V'[1,1])
end
sysuse auto, clear
bootstrap rho_se = r(rho_se): bs_rho_se
/****** end example ******/
For more detailed examples see [R] bootstrap.
-- Yulia
[email protected]
*
* 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/