Announcement

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

  • How to generate leads and lags of binary treatment indicator (say Free Trade Agreements) when treatment assignments turns ON and OFF

    Dear Tom Zylkin !
    I was reading your paper, On the widely differing effects of free trade agreements: Lessons from twenty years of trade integration. JIE (2019), where FTAij,t is an indicator that takes the value 1 were i and j are members of same FTA at time t and is equal to zero otherwise. Further, to estimate the phased-in and lagged effects you include a 5-year lag FTAij,t-5 as an additional regressor.
    In my case, I want to extend the logic to preferential trade agreements (which is also an indicator =1 if two countries are part of PTA at time t and 0 otherwise ). Further, I am using data on consecutive years (annual data) not the interval data as in Anderson and Yotov (2016) which use 4-year interval data or Baier and Bergstrand (2007) which use 5-year interval data.

    I want to create 7 treatment lags (PTAij,t-1 ; PTAij,t-2 ; PTAij,t-3 ; PTAij,t-4 ; PTAij,t-5 ; PTAij,t-6 and PTAij,t-7) to accounts for the possibility that FTA effects may“phase-in” over time. To test whether PTA is strictly "exogenous", I want to additionally generate 4 treatment leads (PTAij,t+1 ; PTAij,t+2 ; PTAij,t+3 ; PTAij,t+4)

    However, the PTA indicator switches ON and OFF for a given country-pair across time, that is; it is 0 from t1-t3, then 1 from t4-t7, 0 from t8-t12 and again 1 from t13-t19 (say). I ran the following codes to obtain how many times does the PTA indicator switches from 0 to 1 across sample time in a given bilateral pair
    Code:
    bysort iso_* (year) : gen counter = sum(pta != pta[_n-1])
    by iso_* : replace counter = counter[_N]
    The counter gives the number of times PTA turns ON and OFF in a given pair across time. I am posting a simple dataex example here to highlight the nature of PTA indicator in my case.
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str1(iso_i iso_j) int year byte pta
    "A" "B" 1995 0
    "A" "B" 1996 0
    "A" "B" 1997 0
    "A" "B" 1998 1
    "A" "B" 1999 1
    "A" "B" 2000 1
    "A" "B" 2001 1
    "A" "B" 2002 1
    "A" "B" 2003 1
    "A" "B" 2004 0
    "A" "B" 2005 0
    "A" "B" 2006 0
    "A" "B" 2007 0
    "A" "B" 2008 0
    "A" "B" 2009 0
    "A" "B" 2010 0
    "A" "B" 2011 0
    "A" "B" 2012 0
    "A" "B" 2013 0
    "A" "B" 2014 1
    "A" "B" 2015 1
    "A" "B" 2016 1
    "A" "B" 2017 1
    end
    The PTA is 0 from 1995-1997, then it is 1 from 1998-2003, then 0 from 2004-2013 and again 1 from 2014-2017. Therefore it switches four time from 0 to 1 between the same country pair across time.

    I am not sure How to generate the PTA leads and lags in this case and whether it makes sense. Please get back to me. I shall be very thankful.

    Thanks and regards,
    (Ridwan)
    Last edited by Ridwan Sheikh; 21 Jul 2023, 01:51.

  • #2
    Hi Ridwan,
    Here is my suggestion:

    sort isoexp isoimp year
    forvalues t = 1(1)4 {
    by isoexp isoimp: gen lead_`t' = (PTA[_n+`t'])*(year[_n+`t'] == year+`t')
    forvalues s = 1(1)`t' {
    by isoexp isoimp: replace lead_`t' = (PTA[_n+`s']) if (year[_n+`s'] == year+`t')
    }
    }

    forvalues t = 1(1)7 {
    by isoexp isoimp: gen lag_`t' = (PTA[_n-`t'])*(year[_n-`t'] == year-`t')
    forvalues s = 1(1)`t' {
    by isoexp isoimp: replace lag_`t' = (PTA[_n-`s']) if (year[_n-`s'] == year-`t')
    }
    }

    The reason for the nested for loop is for if there are missing years within pairs.
    Last edited by Tom Zylkin; 21 Jul 2023, 08:21. Reason: posted an unfinished post by accident

    Comment


    • #3
      Tom Zylkin Thank you very much Sir. This worked fine. I was doing it in a more old-style fashion
      Code:
      * Lags
      
      sort iso_i iso_j year
      
      by iso_i iso_j: gen lag1 = pta[_n-1]
      by iso_i iso_j: gen lag2 = pta[_n-2]
      .
      .
      * Leads
      
      by iso_i iso_j: gen lead1 = pta[_n+1]
      by iso_i iso_j: gen lead2 = pta[_n+2]
      .
      .
      But as you said

      The reason for the nested for loop is for if there are missing years within pairs.
      .
      Thanks for the information and the code. I highly appreciate it.

      Thanks and regards,
      (Ridwan)

      Comment


      • #4
        Dear Tom Zylkin
        First, with 3-year interval data on trade flows (outcome) and pta (treatment), I am using ppmlhdfe to estimate the anticipatory(pta_t+3), contemporaneous (pta_t) and phasing-in (pta_t-3; pta_t-6; pta_t-9) effects of pta. Therefore I run

        Code:
        cap egen isoi = group(iso_i)
        cap egen isoj = group(iso_j)
        
        ppmlhdfe trade ptalead3 pta ptalag3 ptalag6 ptalag9, absorb(isoi#year isoj#year isoi#isoj) cluster(isoi#isoj) d
        Code:
        
        
        Further, as in Weidner and Zylkin (2021), I want to correct for the asymptotic bias in this case (three-way gravity). Therefore I write the following line of codes:

        Code:
        predict lambda
        matrix beta = e(b)
        
        ppml_fe_bias trade ptalead3 pta ptalag3 ptalag6 ptalag9, i(isoi) j(isoj) t(year) lambda(lambda)
        
        ppml_fe_bias trade ptalead3 pta ptalag3 ptalag6 ptalag9, i(isoi) j(isoj) t(year) lambda(lambda) beta(beta)
        Code:
                                       --------------------------------------------------------------------
                                                      original       bias     adjusted SEs  bias-corrected
                                        --------------------------------------------------------------------
                                         ptalead3    0.0377679   -0.0055750   0.0375761      0.0433429    
                                                     (0.0307849)                             (0.0375761)  
                                         pta         -0.0134182   -0.0054711   0.0259650      -0.0079472  
                                                     (0.0227903)                             (0.0259650)  
                                         ptalag3     0.0377138   -0.0046284   0.0242841      0.0423422    
                                                     (0.0211092)                             (0.0242841)*  
                                         ptalag6     0.0065564   0.0031798    0.0304569      0.0033766    
                                                     (0.0251702)                             (0.0304569)  
                                         ptalag9    -0.0755045   0.0097904    0.0362077      -0.0852949  
                                                     (0.0285174)                            (0.0362077)**  
                                        --------------------------------------------------------------------
                                       Standard errors clustered by pair, using a local de-biasing adjustment
                                    to account for estimation noise in the isoi-year and isoj-year fixed effects.
                                                           * p<0.10; ** p<0.05; *** p<0.01
        Code:
        
        
        I hope I have not made any serious coding errors, Plz. Let me know if there is any error in the codes (in case).

        The bias-corrected adjustment changed both the magnitude and significance of the estimated parameters. For example, the magnitude of ptalead3 changes from 0.037 to 0.043. Also, ptalag9 was initially(before bias correction) significant at 1% level with a magnitude of -0.075 with bias-corrected, it becomes significant at 5% with a magnitude slightly higher -0.085 in absolute terms.

        Are these changes the obvious reason of the bias-correction procedure?

        I am asking this because on executing your do-file available on your home page there are no differences on the magnitude of standard gravity variables (ln_distw, contig, colony, fta) with and without bias-correction. But yes, the standard errors after bias-correction are now different from the original model- which makes sense to me.

        But I am not sure if there are significant differences in the magnitude of estimated coefficients (like in my case above) or if the sign switches from being positive to negative, is all that still possible with your bias-correction procedure. Please get back to me.

        Thanks and regards,
        (Ridwan)
        Last edited by Ridwan Sheikh; 26 Jul 2023, 05:23. Reason: accidently posted unfinished

        Comment


        • #5
          Hi Ridwan,

          It doesn't look like there are any coding errors but the first instance of ppml_fe_bias looks unnecessary. The second one should produce the table you showed, which is all the information you need. The changes in magnitude and significance are typical.

          In the example on my github page you mentioned, the reason why the coefficient estimates do not change is because that example is for a "two way" model which does not have exporter-importer fixed effects (the only fixed effects are exporter-year and importer-year.) For two-way models, only the standard errors are biased. If you check the syntax for that case, the call to ppml_fe_bias has the option "twoway" included in order to indicate this.

          Hope this is helpful!

          Regards,
          Tom

          Comment


          • #6
            Thank You Tom Zylkin , that was really useful.
            Regards,
            (Ridwan)

            Comment

            Working...
            X