Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: Re: st: Understanding how lincom gets results after margins


From   "Ariel Linden" <[email protected]>
To   <[email protected]>
Subject   Re: Re: st: Understanding how lincom gets results after margins
Date   Fri, 1 Nov 2013 11:43:22 -0400

Thank you Jeff, for your response. I did not know about the "post" option.

That said, I reran the code (as earlier, with now the added 
post option in the -margins- command) and I am not getting the results I
would expect, and there are some conflicting results from the various
-margins- commands. 

See code below and my comments throughout. Feel free to take this off line
if necessary...

Thanks

Ariel

**** start code ****
*selected output from poisson regression (diff-in-diff estimate is
treated#post  term)
----------------------------------------------------------------------------
------------
                       |               Robust
imaging_post_index_tot |      Coef.   Std. Err.      z    P>|z|     [95%
Conf. Interval]
-----------------------+----------------------------------------------------
------------
                 pilot |
              treated  |   .1664104   .0563062     2.96   0.003     .0560524
.2767685
                       |
            postperiod |
                 post  |  -.0478752   .0665729    -0.72   0.472    -.1783556
.0826052
                       |
      pilot#postperiod |
         treated#post  |   .0047102   .0810194     0.06   0.954    -.1540849
.1635053
-----------------------+----------------------------------------------------
------------

* run margins to get individual values for pre and post for treatment and
controls (with coefl to get code)
. margins postperiod , over(pilot) post coefl

Predictive margins                                Number of obs   =
54794
Model VCE    : Robust

Expression   : Predicted number of events, predict()
over         : pilot

----------------------------------------------------------------------------
------
                 |     Margin  Legend
-----------------+----------------------------------------------------------
------
pilot#postperiod |
    control#pre  |   .0604865  _b[0bn.pilot#0bn.postperiod]
   control#post  |   .0576589  _b[0bn.pilot#1.postperiod]
    treated#pre  |   .0629165  _b[1.pilot#0bn.postperiod]
   treated#post  |   .0602585  _b[1.pilot#1.postperiod]
----------------------------------------------------------------------------
------
* run lincom to get diff-in-diff manually
. lincom (_b[1.pilot#1.postperiod] - _b[1.pilot#0bn.postperiod]) -
(_b[0bn.pilot#1.postperiod] - _b[0bn.pilot#0bn.
> postperiod])

 ( 1)  0bn.pilot#0bn.postperiod - 0bn.pilot#1.postperiod -
1.pilot#0bn.postperiod + 1.pilot#1.postperiod = 0

----------------------------------------------------------------------------
--
             |      Coef.   Std. Err.      z    P>|z|     [95% Conf.
Interval]
-------------+--------------------------------------------------------------
--
         (1) |   .0001696   .0048414     0.04   0.972    -.0093193
.0096585
----------------------------------------------------------------------------
--

* run margins for contrasts (treated post-pre diff and controls post-pre
diff)
. margins r.postperiod@pilot, post

Contrasts of predictive margins
Model VCE    : Robust

Expression   : Predicted number of events, predict()

----------------------------------------------------------
                       |         df        chi2     P>chi2
-----------------------+----------------------------------
      postperiod@pilot |
(post vs pre) control  |          1        0.52     0.4714
(post vs pre) treated  |          1        0.88     0.3484
                Joint  |          2        1.40     0.4970
----------------------------------------------------------

------------------------------------------------------------------------
                       |            Delta-method
                       |   Contrast   Std. Err.     [95% Conf. Interval]
-----------------------+------------------------------------------------
      postperiod@pilot |
(post vs pre) control  |  -.0026417   .0036677     -.0098303     .004547
(post vs pre) treated  |  -.0028196   .0030072     -.0087136    .0030744
------------------------------------------------------------------------

* run lincom to manually estimate diff-in-diff value

. lincom _b[[email protected]]- _b[[email protected]]

 ( 1)  - [email protected] + [email protected] = 0

----------------------------------------------------------------------------
--
             |      Coef.   Std. Err.      z    P>|z|     [95% Conf.
Interval]
-------------+--------------------------------------------------------------
--
         (1) |  -.0001779   .0047435    -0.04   0.970     -.009475
.0091192
----------------------------------------------------------------------------
--

*notes: the margins estimates are not the same, and none of the margins
estimates are the same as the coefficient estimate from the original Poisson
model.


Date: Thu, 31 Oct 2013 16:29:38 -0500
From: [email protected] (Jeff Pitblado, StataCorp LP)
Subject: Re: st: Understanding how lincom gets results after margins

Ariel Linden <[email protected]> is trying to use -lincom- after
- -margins-, but is not getting the expected result:

> After running a poisson regression, I ran -margins- to get individual pre
> and post values for a treatment and control group. Next, I ran -lincom- in
> order to estimate the difference in differences, ie,. (treatment_post -
> treatment_pre) - (control_post - control_pre). 
> 
> The results from -lincom- do not produce the same values as when
calculating
> them manually from the table produced by -margins-. Interestingly enough,
> the results from -lincom- are exactly as those produced in the poisson
> regression table for the interaction treatment#period. Can someone explain
> this discrepancy, and explain how lincom got these results? 
> 
> **** start code****
> 
> . margins postperiod , over(pilot ) coefleg
> 
> Predictive margins                                Number of obs   =
> 54794
> Model VCE    : Robust
> 
> Expression   : Predicted number of events, predict()
> over         : pilot
>
----------------------------------------------------------------------------
> ------
>                  |     Margin  Legend
>
-----------------+----------------------------------------------------------
> ------
> pilot#postperiod |
>     control#pre  |   .0604865  _b[0bn.pilot#0bn.postperiod]
>    control#post  |   .0576589  _b[0bn.pilot#1.postperiod]
>     treated#pre  |   .0629165  _b[1.pilot#0bn.postperiod]
>    treated#post  |   .0602585  _b[1.pilot#1.postperiod]
>
----------------------------------------------------------------------------
> ------  
> 
> lincom (_b[1.pilot#1.postperiod] - _b[1.pilot#0bn.postperiod]) -
> (_b[0bn.pilot#1.postperiod] - _b[0bn.pilot#0bn.postperiod])
> 
> ( 1)  [imaging_post_index_tot]0b.pilot#0b.postperiod -
> [imaging_post_index_tot]0b.pilot#1o.postperiod -
>        [imaging_post_index_tot]1o.pilot#0b.postperiod +
> [imaging_post_index_tot]1.pilot#1.postperiod = 0
> 
>
----------------------------------------------------------------------------
> --
> imaging_po~t |      Coef.   Std. Err.      z    P>|z|     [95% Conf.
> Interval]
>
-------------+--------------------------------------------------------------
> --
>          (1) |   .0047102   .0810194     0.06   0.954    -.1540849
> .1635053
>
----------------------------------------------------------------------------
> --
> 
> * calculating differences in differences manually from -margins- table:
> . di (.0602585 - .0629165) - (.0576589 - .0604865)
> .0001696
> 
> **** end code***

- -lincom- operates on the current estimation results in -e()-.  Without the
- -post- option in the call to -margins-, this means that -lincom- is using
the
- -e()- results from the most currently estimated model.  Ariel needs to
specify
the -post- option with -margins- to get -lincom- to work with -margins- own
estimation results.

We notice that Ariel used the -coeflegend- with -margins- without also
specifying the -post- option.  -margins- should have produced an error
message, because it otherwise gives the impression that -e(b)- is from
margins
instead of the originally fitted estimation.  We will fix this in a future
update to Stata 13.

- --Jeff
[email protected]

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index