Announcement

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

  • factor variables and margins

    Hi,

    I estimate the following regression:

    Code:
    reg Y   ib2001.YEAR  i.AGE,
    where YEAR=2000, 2001,...,2005 and AGE = 0,1,2,...,99. So 2001 becomes the base year.

    I then like set the year-dummies to zero and predict the value of the outcome for each year based on AGE. My idea was to use something like:

    Code:
    margins, by(YEAR) at(i2000.YEAR=0 i2002.YEAR=0 i2003.YEAR=0 i2004.YEAR=0 i2005.YEAR=0)
    However, stata returns:

    HTML Code:
    at values for factor Event do not sum to 1
    So I guess I cannot set the dummies to zero by using i2000.YEAR=0. How can I address factor variables in the margins command?

    Thanks a lot!

  • #2
    I believe that what you want is given by something like
    Code:
    margins age, by(YEAR)
    Consider the following example.
    Code:
    . sysuse auto, clear
    (1978 Automobile Data)
    
    . quietly reg price ib1.rep78 i.foreign
    
    . margins rep78 foreign
    
    Predictive margins                              Number of obs     =         69
    Model VCE    : OLS
    
    Expression   : Linear prediction, predict()
    
    ------------------------------------------------------------------------------
                 |            Delta-method
                 |     Margin   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
           rep78 |
              1  |   4575.687   2146.133     2.13   0.037     286.9831    8864.391
              2  |   5978.812   1105.625     5.41   0.000     3769.397    8188.227
              3  |   6436.745   585.9965    10.98   0.000     5265.724    7607.765
              4  |   6064.308   735.0801     8.25   0.000     4595.368    7533.249
              5  |   5894.113   1043.948     5.65   0.000     3807.949    7980.277
                 |
         foreign |
       Domestic  |   6134.857   474.7025    12.92   0.000     5186.239    7083.474
        Foreign  |   6171.614   790.5026     7.81   0.000      4591.92    7751.307
    ------------------------------------------------------------------------------
    
    . margins rep78, by(foreign)
    
    Predictive margins                              Number of obs     =         69
    Model VCE    : OLS
    
    Expression   : Linear prediction, predict()
    over         : foreign
    
    -------------------------------------------------------------------------------
                  |            Delta-method
                  |     Margin   Std. Err.      t    P>|t|     [95% Conf. Interval]
    --------------+----------------------------------------------------------------
    foreign#rep78 |
      Domestic#1  |     4564.5   2123.983     2.15   0.035     320.0579    8808.942
      Domestic#2  |   5967.625   1061.992     5.62   0.000     3845.404    8089.846
      Domestic#3  |   6425.558   557.6419    11.52   0.000     5311.199    7539.916
      Domestic#4  |   6053.121   869.7847     6.96   0.000     4314.995    7791.248
      Domestic#5  |   5882.926   1226.282     4.80   0.000     3432.396    8333.456
       Foreign#1  |   4601.257   2352.102     1.96   0.055    -99.04312    9301.558
       Foreign#2  |   6004.382   1465.914     4.10   0.000     3074.987    8933.777
       Foreign#3  |   6462.315   1061.992     6.09   0.000     4340.094    8584.536
       Foreign#4  |   6089.879   869.7847     7.00   0.000     4351.752    7828.005
       Foreign#5  |   5919.683   924.1169     6.41   0.000     4072.983    7766.383
    -------------------------------------------------------------------------------
    If you are not already familiar with these papers, you may find a useful explanation of margins, and more, in the nice overview of margins prepared by Richard at https://www3.nd.edu/~rwilliam/xsoc73994/Margins01.pdf with a more detailed paper in the Stata Journal at http://www.stata-journal.com/article...article=st0260. I'll also note that Margins01.pdf is followed by Margins02.pdf ... Margins05.pdf covering more specialized topics. While Richard is writing about categorical dependent variables and logistic regression, the principles are generally the same for continuous dependent variables and linear regression.

    Comment

    Working...
    X