Announcement

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

  • Margins

    Dear Stata community,

    I am evaluating the evolution of sleep duration through a five-year period. I use a structural equation model (SEM) to manage the fact that your past habit of sleep affects your present habit of sleep. For this, I am using data from high school students. Each year, some students came in and others came out of the sample. I use the full information maximum likelihood (FIML) to deal with the missing data and the case that are not presents during the five years. I am really interested in the marginal effects. When I use the command margins, in Stata, it only uses the complete cases. Is there a margins command that also considers cases with missing data? Otherwise, I feel that the margin command does not give me a representative estimate, I go from 37,000 individuals to less than 100 complete cases.

    Thank you for your time,
    Anne
    Last edited by Anne Tremblay; 10 Oct 2022, 23:26.

  • #2
    Originally posted by Anne Tremblay View Post
    feel that the margin command does not give me a representative estimate, I go from 37,000 individuals to less than 100 complete cases.
    FIML does not impute any data, it adjusts the likelihood so that each case contributes information on the observed variables. That said, margins works with the estimates and estimation sample of the previously executed command, notwithstanding the number of observations that it reports. A case in point is linear regression where the coefficients are themselves marginal effects. There is no adjustment to the predicted margins based on missing values.

    Code:
    sysuse auto, clear
    replace rep78=. in 20/35
    regress price mpg weight rep78
    count if e(sample)
    sem (price<-mpg weight rep78),  method(mlmv)
    count if e(sample)
    margins, dydx(*)
    count if e(sample)
    Res.:

    Code:
    . regress price mpg weight rep78
    
          Source |       SS           df       MS      Number of obs   =        53
    -------------+----------------------------------   F(3, 49)        =      7.68
           Model |   127242377         3  42414125.6   Prob > F        =    0.0003
        Residual |   270681798        49  5524118.33   R-squared       =    0.3198
    -------------+----------------------------------   Adj R-squared   =    0.2781
           Total |   397924175        52  7652387.98   Root MSE        =    2350.3
    
    ------------------------------------------------------------------------------
           price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
             mpg |  -70.12284   86.93809    -0.81   0.424    -244.8315    104.5858
          weight |   1.916421   .7070862     2.71   0.009     .4954775    3.337364
           rep78 |   857.4701   348.8883     2.46   0.018     156.3529    1558.587
           _cons |   -947.981   3970.305    -0.24   0.812    -8926.607    7030.645
    ------------------------------------------------------------------------------
    
    .
    . count if e(sample)
      53
    
    .
    . sem (price<-mpg weight rep78),  method(mlmv)
    note: Missing values found in observed exogenous variables. Using the noxconditional behavior. Specify the forcexconditional option to
          override this behavior.
    Endogenous variables
    
    Observed:  price
    
    Exogenous variables
    
    Observed:  mpg weight rep78
    
    Fitting saturated model:
    
    Iteration 0:   log likelihood = -1545.7532  
    Iteration 1:   log likelihood = -1543.6759  
    Iteration 2:   log likelihood = -1543.2863  
    Iteration 3:   log likelihood = -1543.2829  
    Iteration 4:   log likelihood = -1543.2829  
    
    Fitting baseline model:
    
    Iteration 0:   log likelihood = -1559.2294  
    Iteration 1:   log likelihood = -1559.2126  
    Iteration 2:   log likelihood = -1559.2126  
    
    Fitting target model:
    
    Iteration 0:   log likelihood = -1543.2829  
    Iteration 1:   log likelihood = -1543.2829  
    
    Structural equation model                       Number of obs     =         74
    Estimation method  = mlmv
    Log likelihood     = -1543.2829
    
    ----------------------------------------------------------------------------------
                     |                 OIM
                     |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -----------------+----------------------------------------------------------------
    Structural       |
      price          |
                 mpg |  -71.12228   80.49172    -0.88   0.377    -228.8831    86.63858
              weight |   2.119103   .6163165     3.44   0.001     .9111449    3.327061
               rep78 |   900.7545   338.5987     2.66   0.008     237.1133    1564.396
               _cons |  -1751.917   3620.034    -0.48   0.628    -8847.053    5343.219
    -----------------+----------------------------------------------------------------
            mean(mpg)|    21.2973   .6679914    31.88   0.000     19.98806    22.60654
         mean(weight)|   3019.459   89.73439    33.65   0.000     2843.583    3195.336
          mean(rep78)|   3.367555   .1370481    24.57   0.000     3.098945    3.636164
    -----------------+----------------------------------------------------------------
         var(e.price)|    5365011   926036.3                       3825143     7524777
             var(mpg)|   33.01972   5.428409                      23.92416    45.57326
          var(weight)|   595867.3   97959.98                      431730.6    822405.9
           var(rep78)|   1.053624   .2046775                      .7199975    1.541844
    -----------------+----------------------------------------------------------------
      cov(mpg,weight)|   -3580.38   662.6574    -5.40   0.000    -4879.164   -2281.595
       cov(mpg,rep78)|   2.272991   .8329343     2.73   0.006     .6404698    3.905512
    cov(weight,rep78)|  -332.3424   117.5361    -2.83   0.005     -562.709   -101.9758
    ----------------------------------------------------------------------------------
    LR test of model vs. saturated: chi2(0)   =      0.00, Prob > chi2 =      .
    
    .
    . count if e(sample)
      74
    
    .
    . margins, dydx(*)
    
    Average marginal effects                        Number of obs     =         53
    Model VCE    : OIM
    
    Expression   : Linear prediction (Price), predict(xb(price))
    dy/dx w.r.t. : mpg weight rep78
    
    ------------------------------------------------------------------------------
                 |            Delta-method
                 |      dy/dx   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
             mpg |  -71.12228   80.49172    -0.88   0.377    -228.8831    86.63858
          weight |   2.119103   .6163165     3.44   0.001     .9111449    3.327061
           rep78 |   900.7545   338.5987     2.66   0.008     237.1133    1564.396
    ------------------------------------------------------------------------------
    
    .
    . count if e(sample)
      74
    
    .
    Last edited by Andrew Musau; 11 Oct 2022, 04:40.

    Comment

    Working...
    X