Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

Re: st: standard errors after xtmixed, predit.., fitted

 From Jennyfer Wolf To statalist@hsphsun2.harvard.edu Subject Re: st: standard errors after xtmixed, predit.., fitted Date Thu, 22 Dec 2011 12:11:46 +0100

```Dear Steve, thanks again so much!

I have data from different surveys (survey point estimates) and I use
a term for unstructured covariance in my model:

xtmixed wat_tot year_spline1*|| reg1: || reg2: || country2:year_cat,
cov(unstructured).

so I will add an error term for this in my calculation of the fitted
standard error:
scalar sd_cov = exp([atr3_1_1_2]_cons)

Actually wat_tot (the dependent variable) is transformed with logit(),
to restrict observations between 0 and 1 as I am modelling
proportions.

After "predict A, fitted" I use the inlogit() command to get the
backtransformed estimates. However, I had problems to backtransform
the standard errors because when I compared standard errors received
without any transformation of the dependent variable and
backtransformed standard errors received from a transformed dependent
variable, these values were very different. Would you know a solution
to this (is it correct to also backtransform the fitted standard
error) and also (of course) I would like to restrict my confidence
intervals to values between 0 and 1.

One concern rests relating to the confidence intervals I calculate
with the fitted standard errors:
The model fits the individual country data very well and the
predictions for the estimates and the fitted values seem very
sensible, however, the standard error and the CIs calculated with the
method you proposed for the fitted values are huge and actually take
any sense away from making a prediction..
Does that mean I need to mak my model simpler?

Thank you very much for the great support!
Jennyfer

2011/12/22 Steve Samuels <sjsamuels@gmail.com>:
> Jennyfer,
>
> I misunderstood your request: my solution was for an observation chosen at random and it incorrectly omitted the residual SD term, to boot.  Try this.
>
> *******************************************
> webuse productivity, clear
> xtmixed gsp private emp hwy water other unemp ///
>     || region: || state: unemp
>
> matrix list e(b)  //names of terms
> scalar sd_res = exp([lnsig_e]_cons)
>
> predict se_fix,  stdp
> predict se_region se_state_u se_state, reses
> des se* //check against variable labels
> gen se_fitted =  ///
> sqrt(se_fix^2 +se_region^2 +  se_state^2 ///
>  + (unemp*se_state_u)^2 +sd_res^2)
> *******************************************
>
> I think that in your case the last three statements will be:
> ******************************************************************
> predict se_region1 se_region2  se_country_year se_country, rses
> des se*  //check against variable labels
> sqrt(se_fix^2 +se_region1^2 +  se_region2^2 + ///
>  + se_country^2 + (year_cat*se_country_year)^2 +sd_res^2)
> ******************************************************************
>
> Note that these statements assume that there is no correlation between the country and countryXyear random effects, which is what your model implies.  If there is such correlation (and you can test for it), then a covariance term must be added to the estimated standard error.
>
> If you happen to have sample survey data, then be sure to read the section of Survey Data in the manual entry for -xtmixed-.
>
> Steve
> sjsamuels@gmail.com
>
>
> On Dec 21, 2011, at 10:01 AM, Jennyfer Wolf wrote:
>
> Thank you very much for your answer. I've tried it in many different
> variations but I guess there are problems with this approach:
>
> 1. the squared standard deviations that we are adding up are
> describing variation from the fixed effects but, when I understand
> right, not the error of the model
>
> 2. the CIs I need describe the uncertainty for the estimates for each
> country so countries with more datapoints have a narrower CI and also
> for future predictions the CI should get wider (which does not happen
> with the approach you suggested.
>
> I tried gllamm and used the "ci_marg_mu" command after "gllapred x, mu
> marg fsample" but this does not fit to my individual country data and
> still gives me the same CIs no matter how many survey points I have
> per country.
>
> Any more ideas on how to get confidence intervals after "xtmixed" and
> "predict x, fitted" for the predicted values in multilevel modeling?
> (Alternatively with gllamm)
> Thank you very, very much.
>
> Jennyfer
>
>
> 2011/12/17 Steve Samuels <sjsamuels@gmail.com>:
>>
>> Correction: I should not have included the SD for the error term, as it is not part of the fitted value.
>>
>>
>> Here's an example more like yours, but with two levels, not three. I expect that you can take it
>> from here
>> *******************************************
>> webuse productivity, clear
>> xtmixed gsp private emp hwy water other unemp  || region: || state: unemp
>>
>> matrix list e(b)  //names of terms
>> scalar sd_region = exp([lns1_1_1]_cons)
>> scalar sd_state_u  = exp([lns2_1_1]_cons)
>> scalar sd_state   = exp([lns2_1_2]_cons)
>> scalar dir // check these SDs against results
>>
>> predict se_fix,  stdp
>>
>> gen se_fitted =  ///
>>  sqrt(se_fix^2 +sd_region^2 +  sd_state^2 + (unemp*sd_state_u)^2)
>> *******************************************
>>
>
>> Steve
>> sjsamuels@gmail.com
>>
>> On Dec 16, 2011, at 11:34 AM, Jennyfer Wolf wrote:
>>
>> Dear Statalist,
>>
>> sorry for asking the question again, but we are a bit desperate so it
>> would be great if anybody has a solution for my question:
>>
>> Is it possible to get standard errors for the fitted values of a
>> multilevel-model (three levels, random slope and intercept) after
>>
>> xtmixed dep_var indep_var || region1: || region2: || country :year_cat
>> predict var, fitted
>>
>> ?
>>
>> We would like to present the estimated values with a confidence interval?
>> If it is not possible to get the standard errors for the predicted
>> values from Stata, is it possible to calculate these values from the
>> Standard Errors from the individual estimates?
>>
>> Thank you very very much.
>> With kind regards,
>> Jennyfer
>> *
>
> *
> *   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/

*
*   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/
```