Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down at the end of May, and its replacement, **statalist.org** is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
David Torres <torresd@umich.edu> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: How do I graph prediction of mean growth trajectory? |

Date |
Sat, 22 May 2010 11:59:12 -0400 |

Ciao, Diego -------------------------------------------- David Diego Torres, MA(Sociology) PhD Candidate in Sociology Quoting Michael Norman Mitchell <Michael.Norman.Mitchell@gmail.com>:

Dear DavidI think that this is a case where the -margins- command could beyour friend. It won't directly draw the graph that you seek, but Ithink it will be useful for obtaining the adjusted means that youcould then use for drawing a graph. I have created an examplemodeled after your description using the Stata example dataset-nlswork-. I renamed the variables to match your description and fita model based on what I saw in your email. The creating of thedataset and the xtmixed command to fit the model is shown below.... webuse nlswork, clear . * age . rename ttl_exp assess . rename collgrad homeenv . rename c_city trt . rename race matiq. xtmixed ln_w c.age##c.age assess homeenv i.matiq##i.trt || id: ,cov(unstruct)Then, after fitting this model, I used the -margins- command toget the adjusted means (averaging across the other variables in themodel) for ages ranging from 40 to 45 crossed with the three levelsof maternal IQ. This yields 6 (age) times 3 (matiq) = 18 predictedmeans.. margins , at(age=(40(1)45) matiq=(1 2 3))The margins command, by default, is giving the "Average MarginalEffect", which is averaging the across all of the other predictorsin the model. You might be asking yourself, shouldn't these be heldconstant at their mean? (I ask myself this.) On my website, I have apage that describes the difference between "Marginal Effect at theMean" and "Average Marginal Effects", and it shows that althoughthese are different in a logit model, they are identical in a linearmodel. The URL (which may wrap) is....http://www.michaelnormanmitchell.com/stow/marginal-effect-at-mean-vs-average-marginal-effect.html Below I show the commands again with the output... . webuse nlswork, clear (National Longitudinal Survey. Young Women 14-26 years of age in 1968) .. . * age . rename ttl_exp assess . rename collgrad homeenv . rename c_city trt . rename race matiq ... xtmixed ln_w c.age##c.age assess homeenv i.matiq##i.trt || id: ,cov(unstruct)Note: single-variable random-effects specification; covariancestructure set toidentity Performing EM optimization: Performing gradient-based optimization: Iteration 0: log restricted-likelihood = -9818.6258 Iteration 1: log restricted-likelihood = -9818.6258 Computing standard errors:Mixed-effects REML regression Number of obs =28502Group variable: idcode Number of groups =4710Obs per group: min =1avg =6.1max =15Wald chi2(9) =7180.74Log restricted-likelihood = -9818.6258 Prob > chi2 =0.0000------------------------------------------------------------------------------ln_wage | Coef. Std. Err. z P>|z| [95% Conf.Interval]-------------+----------------------------------------------------------------age | .0456086 .0026478 17.22 0.000 .040419.0507983|c.age#c.age | -.0009042 .000044 -20.53 0.000 -.0009905-.0008179|assess | .0450014 .0009785 45.99 0.000 .0430836.0469192homeenv | .3603894 .0117634 30.64 0.000 .3373336.3834452| matiq |2 | -.121281 .0127061 -9.55 0.000 -.1461844-.09637763 | .1005461 .0497622 2.02 0.043 .0030141.1980782|1.trt | .0390282 .0071551 5.45 0.000 .0250044.053052| matiq#trt |2 1 | .0363523 .0137009 2.65 0.008 .0094991.06320553 1 | -.0515755 .0558514 -0.92 0.356 -.1610422.0578911|_cons | .8204718 .0391195 20.97 0.000 .7437989.8971446------------------------------------------------------------------------------ ------------------------------------------------------------------------------Random-effects Parameters | Estimate Std. Err. [95% Conf.Interval]-----------------------------+------------------------------------------------ idcode: Identity |sd(_cons) | .281425 .003769 .274134.28891-----------------------------+------------------------------------------------sd(Residual) | .2962138 .0013607 .2935589.2988928------------------------------------------------------------------------------LR test vs. linear regression: chibar2(01) = 9454.47 Prob >=chibar2 = 0.0000. margins , at(age=(40(1)45) matiq=(1 2 3))Predictive margins Number of obs =28502Expression : Linear prediction, fixed portion, predict() 1._at : age = 40 matiq = 1 2._at : age = 40 matiq = 2 3._at : age = 40 matiq = 3 4._at : age = 41 matiq = 1 5._at : age = 41 matiq = 2 6._at : age = 41 matiq = 3 7._at : age = 42 matiq = 1 8._at : age = 42 matiq = 2 9._at : age = 42 matiq = 3 10._at : age = 43 matiq = 1 11._at : age = 43 matiq = 2 12._at : age = 43 matiq = 3 13._at : age = 44 matiq = 1 14._at : age = 44 matiq = 2 15._at : age = 44 matiq = 3 16._at : age = 45 matiq = 1 17._at : age = 45 matiq = 2 18._at : age = 45 matiq = 3 ------------------------------------------------------------------------------ | Delta-method| Margin Std. Err. z P>|z| [95% Conf.Interval]-------------+---------------------------------------------------------------- _at |1 | 1.552311 .0093973 165.19 0.000 1.5338931.5707292 | 1.444016 .0119263 121.08 0.000 1.4206411.4673923 | 1.634432 .043937 37.20 0.000 1.5483181.7205474 | 1.524682 .0102364 148.95 0.000 1.5046191.5447455 | 1.416388 .0126123 112.30 0.000 1.3916681.4411076 | 1.606804 .0441239 36.42 0.000 1.5203221.6932857 | 1.495245 .0111808 133.73 0.000 1.4733311.5171598 | 1.38695 .0134051 103.46 0.000 1.3606771.4132249 | 1.577366 .0443525 35.56 0.000 1.4904371.66429610 | 1.463999 .0122296 119.71 0.000 1.440031.48796911 | 1.355705 .0143071 94.76 0.000 1.3276631.38374612 | 1.546121 .0446286 34.64 0.000 1.458651.63359113 | 1.430945 .0133814 106.93 0.000 1.4047181.45717214 | 1.322651 .0153192 86.34 0.000 1.2926261.35267615 | 1.513067 .0449583 33.65 0.000 1.424951.60118316 | 1.396083 .014635 95.39 0.000 1.3673991.42476717 | 1.287788 .0164415 78.33 0.000 1.2555641.32001318 | 1.478204 .0453477 32.60 0.000 1.3893241.567084------------------------------------------------------------------------------ .. end of do-file I hope this helps, Best luck, Michael N. Mitchell See the Stata tidbit of the week at... http://www.MichaelNormanMitchell.com On 2010-05-21 2.27 PM, David Torres wrote:Hello all,I am trying to graph expected growth in IQ scores by maternal IQclass and treatment/control group assignment. Since there arethree maternal IQ classes and two group assignments, I should havesix lines or growth curves.Now, my models were calculated using Stata's -xtmixed- command, soI've been following Rabe-Hesketh and Skrondal's text on multilevelmodeling, 2nd edition, page 210-220. They give an example of howto graph growth, but the example does not include interactions nordoes it allow for the slopes to change between some othertime-varying covariate, which I have in my model. The outcome istest score, of course. The list of the predictor variables in thefull model from which I would like to create my graphs follow:1. age 2. age^2 3. assessment given (two different assessments over several years, so this is entered as a time-varying covariate. It would be great if I could get the slope to vary by assessment) - Stanford-Binet or Wechsler 4. home environment - 0/1, less stimulating/more stimulating 5. treatment - 0/1, control/treatment 6 & 7. maternal IQ class - 1/2/3, IQ<=75/IQ between 76&90/IQ between 91&110 1 is the reference category 8 & 9. interaction between treatment and maternal IQ classAll of the variables in this model are significant, so I want tomake sure that my graph accurately reflects that. Also, Iunderstand that since interactions can be difficult to interpretsometimes a visual represention of the data are always good as anaccompaniment.A related question is this: If I have to produce these linesseparately, creating six graphs, is there a way I can overlay them?-------------------------------------------- David Diego Torres, MA(Sociology) PhD Candidate in Sociology * * 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/

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

**Follow-Ups**:**Re: st: How do I graph prediction of mean growth trajectory?***From:*Michael Norman Mitchell <Michael.Norman.Mitchell@gmail.com>

**References**:**st: How do I graph prediction of mean growth trajectory?***From:*David Torres <torresd@umich.edu>

**Re: st: How do I graph prediction of mean growth trajectory?***From:*Michael Norman Mitchell <Michael.Norman.Mitchell@gmail.com>

- Prev by Date:
**Re: st: Assigning values from a list** - Next by Date:
**[no subject]** - Previous by thread:
**Re: st: How do I graph prediction of mean growth trajectory?** - Next by thread:
**Re: st: How do I graph prediction of mean growth trajectory?** - Index(es):