Stata Margins

The margins command reports expected values from a model.


Usage

Adapted from here:

. webuse nhanes2l
(Second National Health and Nutrition Examination Survey)

. regress bpsystol i.hlthstat##i.diabetes

      Source |       SS           df       MS      Number of obs   =    10,335
-------------+----------------------------------   F(9, 10325)     =     86.92
       Model |  396524.045         9  44058.2272   Prob > F        =    0.0000
    Residual |  5233449.31    10,325  506.871604   R-squared       =    0.0704
-------------+----------------------------------   Adj R-squared   =    0.0696
       Total |  5629973.35    10,334  544.800982   Root MSE        =    22.514

-------------------------------------------------------------------------------------
           bpsystol | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
--------------------+----------------------------------------------------------------
           hlthstat |
         Very good  |   2.636051   .6417076     4.11   0.000      1.37818    3.893922
              Good  |   7.648725   .6272209    12.19   0.000     6.419251      8.8782
              Fair  |   13.50647   .7408272    18.23   0.000      12.0543    14.95863
              Poor  |   14.77223   1.032484    14.31   0.000     12.74837     16.7961
                    |
           diabetes |
          Diabetic  |   5.780232   4.618696     1.25   0.211    -3.273308    14.83377
                    |
  hlthstat#diabetes |
Very good#Diabetic  |   17.43339   5.726714     3.04   0.002     6.207924    28.65886
     Good#Diabetic  |   4.023894   5.032308     0.80   0.424    -5.840404    13.88819
     Fair#Diabetic  |   7.316062    4.97969     1.47   0.142    -2.445096    17.07722
     Poor#Diabetic  |   3.445358    5.09316     0.68   0.499    -6.538222    13.42894
                    |
              _cons |   124.2614   .4611975   269.43   0.000     123.3574    125.1655
-------------------------------------------------------------------------------------

. margins i.hlthstat#i.diabetes

Adjusted predictions                                    Number of obs = 10,335
Model VCE: OLS

Expression: Linear prediction, predict()

-----------------------------------------------------------------------------------------
                        |            Delta-method
                        |     Margin   std. err.      t    P>|t|     [95% conf. interval]
------------------------+----------------------------------------------------------------
      hlthstat#diabetes |
Excellent#Not diabetic  |   124.2614   .4611975   269.43   0.000     123.3574    125.1655
    Excellent#Diabetic  |   130.0417   4.595612    28.30   0.000     121.0334      139.05
Very good#Not diabetic  |   126.8975   .4461899   284.40   0.000     126.0229    127.7721
    Very good#Diabetic  |   150.1111   3.356161    44.73   0.000     143.5324    156.6898
     Good#Not diabetic  |   131.9102   .4250916   310.31   0.000     131.0769    132.7434
         Good#Diabetic  |   141.7143   1.952195    72.59   0.000     137.8876     145.541
     Fair#Not diabetic  |   137.7679   .5797601   237.63   0.000     136.6315    138.9043
         Fair#Diabetic  |   150.8642   1.768852    85.29   0.000     147.3969    154.3315
     Poor#Not diabetic  |   139.0337   .9237528   150.51   0.000     137.2229    140.8444
         Poor#Diabetic  |   148.2593    1.93768    76.51   0.000      144.461    152.0575
-----------------------------------------------------------------------------------------


See also

Stata manual for margins


CategoryRicottone

Stata/Margins (last edited 2024-10-15 21:52:34 by DominicRicottone)