Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Linear regression mixed effects graph

    Hi,
    I'm using Stata 12 and I've a problem with a graphics of a linear regression with mixed effects. Tempomesi is a continuous variable while trattato is binary.

    Code:
    . xtmixed ild c.tempomesi##i.trattato || pid:, mle nolog variance 
    
    Mixed-effects ML regression                     Number of obs      =       143
    Group variable: pid                             Number of groups   =        61
    
                                                    Obs per group: min =         2
                                                                   avg =       2.3
                                                                   max =         6
    
    
                                                    Wald chi2(3)       =     28.76
    Log likelihood =  -550.1897                     Prob > chi2        =    0.0000
    
    --------------------------------------------------------------------------------------
                     ild |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
    ---------------------+----------------------------------------------------------------
               tempomesi |   .3300396   .0657651     5.02   0.000     .2011423    .4589369
              1.trattato |  -3.826831   4.163937    -0.92   0.358      -11.988    4.334336
                         |
    trattato#c.tempomesi |
                      1  |  -.2629648   .1021319    -2.57   0.010    -.4631397   -.0627899
                         |
                   _cons |   20.78178   3.101511     6.70   0.000     14.70293    26.86063
    --------------------------------------------------------------------------------------
    
    ------------------------------------------------------------------------------
      Random-effects Parameters  |   Estimate   Std. Err.     [95% Conf. Interval]
    -----------------------------+------------------------------------------------
    pid: Identity                |
                      var(_cons) |   226.6245    44.9081      153.6852     334.181
    -----------------------------+------------------------------------------------
                   var(Residual) |   43.09052   6.757185       31.6885    58.59517
    ------------------------------------------------------------------------------
    LR test vs. linear regression: chibar2(01) =    96.58 Prob >= chibar2 = 0.0000
    When I graph this regression with this command:
    Code:
    twoway (lfit ild tempomesi if trattato==0) (lfit ild tempomesi if trattato==1)
    but red line is wrong. Why?
    Attached Files

  • #2
    That is because lfit just looks at a linear model and does not take into account panel nature of your data. To display your model you need to use margins and marginsplot, e.g.:

    Code:
    version 12
    webuse nlswork, clear
    xtmixed ln_w i.union##c.grade || id:
    margins, over(grade union)
    marginsplot
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Ok, but can i obtain only the predicted line?
      Thank you anyway
      Attached Files

      Comment


      • #4
        Mission accomplished, I do it

        Comment

        Working...
        X