Announcement

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

  • Parallel trends assumption with continuous treatment variable - DiD

    Hi,

    I have survey data on individual firms from 2008-2017. I want to test how a reform that happened in 2013 that affected all individuals influenced their earnings. My testing hypothesis is that the effect is going to be dependent on the level of pre-reform competition (measured by number of rival firms in 3km radius). So my treatment variable is "dd3 = reform=(years>=2014) * prereform_comp".

    From response received on my one previous post (https://www.statalist.org/forums/for...t-observations), on a related issue, I note Stata comand xtdidregress does not yet support graphical diagnostics for parallel trends assumption for continuous treatment. And the ways to do it are generally in the spirit when treatment variable is a dummy instead of continuous.

    1. My main model accounts for individual and time fixed effects and takes the form of:
    reghdfe `outcome' dd3 $controls, absorb(id years) vce(cluster id)


    2. In my analysis, I also run model specification to analyse how the impact would be different for individuals facing different levels (quartiles) of pre-reform competition. This is modelled as below:
    reghdfe `outcome' dd3 $controls, absorb(id years) vce(cluster id)

    where dd3 now is: dd3 = reform=(years>=2014) * quartile_3km*prereform_comp". Quartile1 is my omitted category here.


    Now I would like to test if parallel trends assumption hold in my analysis.

    I am attaching a sample of observations that I have. Any help to test diagnostics for parallel trends assumption would be most appreciated.

    Thanks.


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input long xwaveid float(years lannualY dd3) byte quartile_3km float hrs
    1100002 2008 11.686398     0 1   32
    1100002 2009 11.997396     0 1   36
    1100002 2010  11.85281     0 1   34
    1100002 2011 12.017887     0 1   36
    1100002 2012 11.614816     0 1   34
    1100002 2013 11.682918     0 1   30
    1100005 2008  12.74331     0 1   36
    1100005 2010 12.758693     0 1   32
    1100005 2011 12.752957     0 1   41
    1100008 2008  12.59228     0 2   55
    1100008 2009 12.577435     0 2   50
    1100008 2010 12.639094     0 2   50
    1100008 2011  12.41624     0 2   48
    1100008 2012 12.679445     0 2   47
    1100008 2013  12.38578     0 2   48
    1100008 2014 12.518613    39 2   40
    1100008 2015  12.47567    39 2   31
    1100010 2011  12.26209     0 2   35
    1100010 2014 12.788903    41 2   35
    1100010 2016 11.567077    41 2   30
    1100011 2008 12.194057     0 1   38
    1100011 2009 12.345364     0 1   32
    1100011 2010 12.163589     0 1   35
    1100011 2011 11.619886     0 1   25
    1100012 2008  11.00119     0 4   12
    1100012 2009 11.150636     0 4   18
    1100012 2011 11.163477     0 4   20
    1100012 2012 11.502678     0 4   32
    1100012 2013 12.120378     0 4   30
    1100012 2014 11.673064 124.4 4   35
    1100012 2015  11.87079 124.4 4   35
    1100012 2016 12.270066 124.4 4   30
    1100012 2017  11.98143 124.4 4   33
    1100013 2008  12.57995     0 4   33
    1100013 2009  13.01717     0 4   41
    1100013 2010 12.785512     0 4   46
    1100013 2013  13.03439     0 4   50
    1100014 2008 10.430075     0 3   21
    1100014 2009 10.281137     0 3   11
    1100014 2010   9.88554     0 3   20
    1100021 2008   11.9355     0 3   30
    1100021 2009 11.795596     0 3   36
    1100021 2010 11.405168     0 3   25
    1100021 2011 11.704503     0 3   29
    1100021 2012  11.44317     0 3   30
    1100021 2013  11.83622     0 3   32
    1100028 2008 11.156384     0 4   16
    1100028 2009 11.494257     0 4   15
    1100028 2010 11.583652     0 4   18
    1100028 2011 11.855001     0 4   18
    1100028 2012  11.44317     0 4   18
    1100028 2013 11.478524     0 4   18
    1100028 2014 12.241905 137.2 4   19
    1100028 2015 12.293347 137.2 4   19
    1100028 2016 11.781213 137.2 4   21
    1100028 2017 12.045792 137.2 4   23
    1100030 2009  11.52969     0 2   17
    1100030 2010  11.65244     0 2   26
    1100030 2011 11.677086     0 2   29
    1100030 2012  11.73967     0 2   28
    1100030 2013  11.83622     0 2   32
    1100030 2015 11.804792  27.2 2   31
    1100030 2016  11.81769  27.2 2   27
    1100030 2017 11.259967  27.2 2   33
    1100031 2009 10.720964     0 1   18
    1100031 2011 10.086025     0 1   14
    1100031 2012 10.327307     0 1   17
    1100032 2009 13.217962     0 2   54
    1100032 2010  12.98266     0 2   60
    1100032 2011 12.950105     0 2   50
    1100032 2012 13.058546     0 2   50
    1100032 2013 12.908464     0 2   50
    1100032 2014  12.89323  42.2 2   38
    1100032 2015  12.62509  42.2 2   48
    1100032 2016 12.770346  42.2 2   50
    1100032 2017 12.844865  42.2 2   45
    1100035 2008 12.320346     0 1   42
    1100035 2012 11.860375     0 1   46
    1100036 2008  12.09435     0 2 40.5
    1100036 2009  11.76374     0 2   30
    1100036 2010 11.421727     0 2   30
    1100036 2011  11.47933     0 2   30
    1100036 2013 11.419016     0 2   26
    1100036 2014  11.97863  29.8 2   24
    1100036 2016  11.76276  29.8 2   24
    1100036 2017 10.661768  29.8 2   27
    1100037 2012  12.41897     0 3   43
    1100037 2015 12.825226  55.2 3   40
    1100037 2016 13.234243  55.2 3   40
    1100037 2017 12.799034  55.2 3   42
    1100040 2008 11.200836     0 4   17
    1100040 2009  11.35276     0 4   17
    1100040 2010 11.768997     0 4   21
    1100040 2012 12.163022     0 4   25
    1100040 2013  11.92321     0 4   28
    1100040 2014 12.321003 226.8 4   30
    1100040 2015  12.18087 226.8 4   30
    1100040 2016  12.34998 226.8 4   27
    1100040 2017  12.23112 226.8 4 26.5
    1100043 2008 11.088202     0 2   36
    end
    label values quartile_3km quartile_3km
    label def quartile_3km 1 "Quartile 1 of competition", modify
    label def quartile_3km 2 "Quartile 2 of competition", modify
    label def quartile_3km 3 "Quartile 3 of competition", modify
    label def quartile_3km 4 "Quartile 4 of competition", modify
    Last edited by Kushneel Prakash; 25 Nov 2021, 20:01.

  • #2
    You may always conduct the DiD analysis manually. Below is an example code based on your example data.

    Code:
    gen prereform_comp = dd3 if year >= 2014
    bys xwaveid (prereform_comp): replace prereform_comp = prereform_comp[_n-1] if prereform_comp == .
    gen post = year >= 2014
    
    reghdfe lannualY c.prereform_comp#c.post, absorb(xwaveid year) vce(cl xwaveid)  //main analysis
    reghdfe lannualY c.prereform_comp##ib(2013).year, absorb(xwaveid year) vce(cl xwaveid)    //regression for parallel trend test
    
    mat results = r(table)["b", "2008.years#c.prereform_comp".."2017.years#c.prereform_comp"] \ ///
                  r(table)["ll".."ul", "2008.years#c.prereform_comp".."2017.years#c.prereform_comp"]              
    mat results = results'
    svmat results, n(col)
    gen t = _n + 2007 if !mi(b)
    
    twoway connected b t || rcap ll ul t, ///
           yline(0,lp(dash)) ytitle("Coefficients and 95% CI") ///
           xlab(2008(1)2017) xtitle("Year") leg(off)
    The estimates in red should be insignificant for parallel trends.

    Code:
               years#|
    c.prereform_comp |
               2008  |  -.0064131   .0023889    -2.68   0.028     -.011922   -.0009042
               2009  |   -.003968   .0016759    -2.37   0.045    -.0078325   -.0001034
               2010  |  -.0011945   .0009987    -1.20   0.266    -.0034976    .0011086
               2011  |  -.0016972   .0037408    -0.45   0.662    -.0103234     .006929
               2012  |   .0001154   .0019519     0.06   0.954    -.0043856    .0046164
               2014  |     .00022   .0018587     0.12   0.909    -.0040661    .0045061
               2015  |   .0021329   .0015046     1.42   0.194    -.0013368    .0056025
               2016  |   .0022264   .0012727     1.75   0.118    -.0007086    .0051613
               2017  |     .00446   .0018032     2.47   0.039     .0003018    .0086182
    Below is a coefficient plot.

    Click image for larger version

Name:	Graph.png
Views:	1
Size:	329.5 KB
ID:	1638180

    Comment


    • #3
      Fantastic Fei. Thank you so much.

      Yes, that works. I wonder plotting the same with marginsplot command will also be alright.

      However, if for instance one of the years like 2008 turns out to be significant, does it mean parallel trends assumption is invalid and/or does it make our entire results not reliable. Or we could say something like, 'it is generally valid". What are the recommended norms in this instance?

      Thanks again.

      Comment


      • #4
        I would conclude that there might be a somewhat clear pre-trend before 2014, although only the 2008 coefficient is significant (2009, too). To handle this, I would add an interaction of prereform_com and linear year trend to capture this pre-trend, as below.

        Code:
        reghdfe lannualY c.prereform_comp#c.post c.prereform_comp#c.year, absorb(xwaveid year) vce(cl xwaveid)
        Results also show a significant effect of the interaction -- Another way of implying the likely failure of the parallel trend assumption. But now, the coefficient of c.prereform_comp#c.post would be a more convincing estimate of the policy effect.

        Code:
        -----------------------------------------------------------------------------------
                          |               Robust
                 lannualY |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
        ------------------+----------------------------------------------------------------
         c.prereform_comp#|
                   c.post |  -.0016983   .0017265    -0.98   0.354    -.0056796     .002283
                          |
         c.prereform_comp#|
                  c.years |   .0012163   .0004051     3.00   0.017      .000282    .0021505
                          |
                    _cons |  -204.7549   72.19038    -2.84   0.022    -371.2262   -38.28357
        -----------------------------------------------------------------------------------

        Comment


        • #5
          hello Fei Wang, I really glad reading your comment. I'm working with reghdfe for DiD model and looking for the way to test parallel trend. What does c. mean?

          Comment


          • #6
            c. and i. belong to factor variable notation.

            For instance, to compute an interaction term in a Mincerian regression, you would type:
            Code:
            c.age#i.female
            to get the differential returns to age according to gender. c. before age as age is continuous, i. before female as female is a binary variable.

            This notation really helps to get marginal effects for instance.

            There is now way to prove parallel trends; you can indeed run tests to make your narrative more plausible, but it's really about having a good argumentation.

            Comment

            Working...
            X