Announcement

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

  • xthdidregress vs csdid

    Hello,
    I am investigating the effect of a environmental policy on corporate innovation (patents, r&d expenditure). There are 3 phases, and the treatment sometimes stops at phase 1, 2 for some firms(very few).
    I am deciding whether to remove those firms and run xthdidregress for staggered effect or csdid. I have experience with using xthdidregress but not csdid. I am studying csdid, but I am not really understanding it. I especially do not understand how to setup gvar (treatment group identifier) in the syntax below:.
    csdid depvar [indepvars] [if] [in] [weight], [ivar(varname)] time(varname) gvar(varname) [ options ]
    My current treatment varialbe looks as follows:

    Firm / Year / Treatment
    A 2012 0

    A 2013 0

    A 2014 0

    A 2015 1

    ......

    A 2020 1

    A 2021 0

    A 2022 0

    A 2023 0



    Can someone explain what the gvar(varname) is supposed to be and how to chang my current treatment variable to fit the syntax?

    Kind regards,
    Pak

  • #2
    Hi Hwanseong,

    Please read the following comparison:


    Code:
    . use https://www.stata-press.com/data/r18/akc, clear
    (Fictional dog breed and AKC registration data)
    
    . xtset breed year
    
    Panel variable: breed (strongly balanced)
     Time variable: year, 2031 to 2040
             Delta: 1 unit
    
    . *-xthdidregress ra- vs -csdid, method(reg)-
    . xthdidregress ra (registered best) (movie), group(breed)  ///
    >         cohortvar(cohort, replace) nolog
    note: variable cohort, containing cohort indicators formed by treatment variable movie and group variable breed, was added to the dataset.
    
    Treatment and time information
    
    Time variable: year
    Time interval: 2031 to 2040
    Control:       cohort = 0
    Treatment:     cohort > 0
    -----------------------------
                      |    cohort
    ------------------+----------
    Number of cohorts |         4
    ------------------+----------
    Number of obs     |
        Never treated |      1190
                 2034 |        40
                 2036 |        30
                 2037 |       150
    -----------------------------
    
    Heterogeneous-treatment-effects regression            Number of obs    = 1,410
                                                          Number of panels =   141
    Estimator:       Regression adjustment
    Panel variable:  breed
    Treatment level: breed
    Control group:   Never treated
    
                                    (Std. err. adjusted for 141 clusters in breed)
    ------------------------------------------------------------------------------
                 |               Robust
    Cohort       |       ATET   std. err.      z    P>|z|     [95% conf. interval]
    -------------+----------------------------------------------------------------
    2034         |
            year |
           2032  |  -254.8927   266.1024    -0.96   0.338    -776.4439    266.6584
           2033  |  -257.5329   217.9389    -1.18   0.237    -684.6852    169.6194
           2034  |   701.1318   127.0935     5.52   0.000     452.0331    950.2304
           2035  |   1099.044   282.0704     3.90   0.000      546.196    1651.892
           2036  |   1367.632   225.8702     6.05   0.000     924.9343    1810.329
           2037  |   2008.294   237.2396     8.47   0.000     1543.313    2473.275
           2038  |   2472.624   278.2949     8.88   0.000     1927.176    3018.072
           2039  |   2689.615   504.3324     5.33   0.000     1701.142    3678.088
           2040  |    3110.97    568.916     5.47   0.000     1995.915    4226.025
    -------------+----------------------------------------------------------------
    2036         |
            year |
           2032  |   216.0259   122.9107     1.76   0.079    -24.87472    456.9265
           2033  |  -172.5154   372.0776    -0.46   0.643    -901.7741    556.7433
           2034  |  -218.0495   504.5267    -0.43   0.666    -1206.904    770.8045
           2035  |    621.033   156.1306     3.98   0.000     315.0227    927.0434
           2036  |   999.0781   180.1055     5.55   0.000     646.0779    1352.078
           2037  |   1003.333   250.5916     4.00   0.000     512.1829    1494.484
           2038  |   1556.669   451.6914     3.45   0.001     671.3697    2441.967
           2039  |   2590.674   662.6979     3.91   0.000      1291.81    3889.538
           2040  |   2225.712   486.9917     4.57   0.000     1271.225    3180.198
    -------------+----------------------------------------------------------------
    2037         |
            year |
           2032  |   -114.582   160.0972    -0.72   0.474    -428.3668    199.2028
           2033  |  -127.9856   183.3941    -0.70   0.485    -487.4315    231.4603
           2034  |   33.40901   168.0312     0.20   0.842    -295.9262    362.7442
           2035  |   130.3495   166.2261     0.78   0.433    -195.4477    456.1468
           2036  |  -10.48288   167.5059    -0.06   0.950    -338.7884    317.8226
           2037  |   1717.016   268.5592     6.39   0.000      1190.65    2243.383
           2038  |   2086.798   278.0215     7.51   0.000     1541.886     2631.71
           2039  |   2473.611    268.186     9.22   0.000     1947.976    2999.246
           2040  |   2835.117   378.6699     7.49   0.000     2092.938    3577.296
    ------------------------------------------------------------------------------
    Note: ATET computed using covariates.
    Note: Base time for pretreatment ATETs is the previous period.
    
    . csdid registered best, ivar(breed) time(year) gvar(cohort) method(reg)
    ...........................
    Difference-in-difference with Multiple Time Periods
    
                                                             Number of obs = 1,410
    Outcome model  : regression adjustment
    Treatment model: none
    ------------------------------------------------------------------------------
                 | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
    -------------+----------------------------------------------------------------
    g2034        |
     t_2031_2032 |  -254.8927   266.1024    -0.96   0.338    -776.4439    266.6584
     t_2032_2033 |  -257.5329   217.9389    -1.18   0.237    -684.6852    169.6194
     t_2033_2034 |   701.1318   127.0935     5.52   0.000     452.0331    950.2304
     t_2033_2035 |   1099.044   282.0704     3.90   0.000      546.196    1651.892
     t_2033_2036 |   1367.632   225.8702     6.05   0.000     924.9343    1810.329
     t_2033_2037 |   2008.294   237.2396     8.47   0.000     1543.313    2473.275
     t_2033_2038 |   2472.624   278.2949     8.88   0.000     1927.176    3018.072
     t_2033_2039 |   2689.615   504.3324     5.33   0.000     1701.142    3678.088
     t_2033_2040 |    3110.97    568.916     5.47   0.000     1995.915    4226.025
    -------------+----------------------------------------------------------------
    g2036        |
     t_2031_2032 |   216.0259   122.9107     1.76   0.079    -24.87472    456.9265
     t_2032_2033 |  -172.5154   372.0776    -0.46   0.643    -901.7741    556.7433
     t_2033_2034 |  -218.0495   504.5267    -0.43   0.666    -1206.904    770.8045
     t_2034_2035 |    621.033   156.1306     3.98   0.000     315.0227    927.0434
     t_2035_2036 |   999.0781   180.1055     5.55   0.000     646.0779    1352.078
     t_2035_2037 |   1003.333   250.5916     4.00   0.000     512.1829    1494.484
     t_2035_2038 |   1556.669   451.6914     3.45   0.001     671.3697    2441.967
     t_2035_2039 |   2590.674   662.6979     3.91   0.000      1291.81    3889.538
     t_2035_2040 |   2225.712   486.9917     4.57   0.000     1271.225    3180.198
    -------------+----------------------------------------------------------------
    g2037        |
     t_2031_2032 |   -114.582   160.0972    -0.72   0.474    -428.3668    199.2028
     t_2032_2033 |  -127.9856   183.3941    -0.70   0.485    -487.4315    231.4603
     t_2033_2034 |   33.40901   168.0312     0.20   0.842    -295.9262    362.7442
     t_2034_2035 |   130.3495   166.2261     0.78   0.433    -195.4477    456.1468
     t_2035_2036 |  -10.48288   167.5059    -0.06   0.950    -338.7884    317.8226
     t_2036_2037 |   1717.016   268.5592     6.39   0.000      1190.65    2243.383
     t_2036_2038 |   2086.798   278.0215     7.51   0.000     1541.886     2631.71
     t_2036_2039 |   2473.611    268.186     9.22   0.000     1947.976    2999.246
     t_2036_2040 |   2835.117   378.6699     7.49   0.000     2092.938    3577.296
    ------------------------------------------------------------------------------
    Control: Never Treated
    
    See Callaway and Sant'Anna (2021) for details
    
    . 
    . *-xthdidregress aipw- vs -csdid, method(dripw)-
    . xthdidregress aipw (registered best) (movie best), group(breed)  ///
    >          cohortvar(cohort, replace) nolog
    note: variable cohort, containing cohort indicators formed by treatment variable movie and group variable breed, was added to the dataset.
    
    Treatment and time information
    
    Time variable: year
    Time interval: 2031 to 2040
    Control:       cohort = 0
    Treatment:     cohort > 0
    -----------------------------
                      |    cohort
    ------------------+----------
    Number of cohorts |         4
    ------------------+----------
    Number of obs     |
        Never treated |      1190
                 2034 |        40
                 2036 |        30
                 2037 |       150
    -----------------------------
    
    Heterogeneous-treatment-effects regression            Number of obs    = 1,410
                                                          Number of panels =   141
    Estimator:       Augmented IPW
    Panel variable:  breed
    Treatment level: breed
    Control group:   Never treated
    
                                    (Std. err. adjusted for 141 clusters in breed)
    ------------------------------------------------------------------------------
                 |               Robust
    Cohort       |       ATET   std. err.      z    P>|z|     [95% conf. interval]
    -------------+----------------------------------------------------------------
    2034         |
            year |
           2032  |  -254.8927   266.1024    -0.96   0.338    -776.4439    266.6584
           2033  |  -257.5329   217.9389    -1.18   0.237    -684.6852    169.6194
           2034  |   701.1318   127.0935     5.52   0.000     452.0331    950.2305
           2035  |   1099.044   282.0704     3.90   0.000      546.196    1651.892
           2036  |   1367.632   225.8702     6.05   0.000     924.9343    1810.329
           2037  |   2008.294   237.2396     8.47   0.000     1543.313    2473.275
           2038  |   2472.624   278.2949     8.88   0.000     1927.176    3018.072
           2039  |   2689.615   504.3324     5.33   0.000     1701.142    3678.088
           2040  |    3110.97    568.916     5.47   0.000     1995.915    4226.024
    -------------+----------------------------------------------------------------
    2036         |
            year |
           2032  |   216.0259   122.9107     1.76   0.079    -24.87472    456.9265
           2033  |  -172.5154   372.0776    -0.46   0.643    -901.7741    556.7433
           2034  |  -218.0495   504.5267    -0.43   0.666    -1206.904    770.8046
           2035  |    621.033   156.1306     3.98   0.000     315.0227    927.0433
           2036  |   999.0781   180.1055     5.55   0.000     646.0779    1352.078
           2037  |   1003.333   250.5916     4.00   0.000     512.1829    1494.484
           2038  |   1556.668   451.6914     3.45   0.001     671.3697    2441.967
           2039  |   2590.674   662.6979     3.91   0.000      1291.81    3889.538
           2040  |   2225.712   486.9917     4.57   0.000     1271.225    3180.198
    -------------+----------------------------------------------------------------
    2037         |
            year |
           2032  |   -121.857   159.0273    -0.77   0.444    -433.5448    189.8307
           2033  |  -136.1117   182.3992    -0.75   0.456    -493.6076    221.3843
           2034  |   35.53022   166.7673     0.21   0.831    -291.3276    362.3881
           2035  |   138.6257   164.9303     0.84   0.401    -184.6318    461.8832
           2036  |  -11.14846   166.5179    -0.07   0.947    -337.5176    315.2207
           2037  |   1826.033   268.0048     6.81   0.000     1300.753    2351.313
           2038  |   2219.293   277.3226     8.00   0.000     1675.751    2762.836
           2039  |   2630.665   267.4985     9.83   0.000     2106.378    3154.953
           2040  |   3015.125    378.255     7.97   0.000     2273.758    3756.491
    ------------------------------------------------------------------------------
    Note: ATET computed using covariates.
    Note: Base time for pretreatment ATETs is the previous period.
    
    . csdid registered best, ivar(breed) time(year) ///
    >         gvar(cohort) method(dripw)               
    ...........................
    Difference-in-difference with Multiple Time Periods
    
                                                             Number of obs = 1,410
    Outcome model  : least squares
    Treatment model: inverse probability
    ------------------------------------------------------------------------------
                 | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
    -------------+----------------------------------------------------------------
    g2034        |
     t_2031_2032 |  -254.8927   266.1024    -0.96   0.338    -776.4439    266.6584
     t_2032_2033 |  -257.5329   217.9389    -1.18   0.237    -684.6852    169.6194
     t_2033_2034 |   701.1318   127.0935     5.52   0.000     452.0331    950.2304
     t_2033_2035 |   1099.044   282.0704     3.90   0.000      546.196    1651.892
     t_2033_2036 |   1367.632   225.8702     6.05   0.000     924.9343    1810.329
     t_2033_2037 |   2008.294   237.2396     8.47   0.000     1543.313    2473.275
     t_2033_2038 |   2472.624   278.2949     8.88   0.000     1927.176    3018.072
     t_2033_2039 |   2689.615   504.3324     5.33   0.000     1701.142    3678.088
     t_2033_2040 |    3110.97    568.916     5.47   0.000     1995.915    4226.025
    -------------+----------------------------------------------------------------
    g2036        |
     t_2031_2032 |   216.0259   122.9107     1.76   0.079    -24.87472    456.9265
     t_2032_2033 |  -172.5154   372.0776    -0.46   0.643    -901.7741    556.7433
     t_2033_2034 |  -218.0495   504.5267    -0.43   0.666    -1206.904    770.8045
     t_2034_2035 |    621.033   156.1306     3.98   0.000     315.0227    927.0434
     t_2035_2036 |   999.0781   180.1055     5.55   0.000     646.0779    1352.078
     t_2035_2037 |   1003.333   250.5916     4.00   0.000     512.1829    1494.484
     t_2035_2038 |   1556.669   451.6914     3.45   0.001     671.3697    2441.967
     t_2035_2039 |   2590.674   662.6979     3.91   0.000      1291.81    3889.538
     t_2035_2040 |   2225.712   486.9917     4.57   0.000     1271.225    3180.198
    -------------+----------------------------------------------------------------
    g2037        |
     t_2031_2032 |   -121.857   169.1243    -0.72   0.471    -453.3345    209.6204
     t_2032_2033 |  -136.1117   193.9801    -0.70   0.483    -516.3057    244.0824
     t_2033_2034 |   35.53022   177.3557     0.20   0.841    -312.0805    383.1409
     t_2034_2035 |   138.6257   175.4021     0.79   0.429    -205.1561    482.4075
     t_2035_2036 |  -11.14846   177.0905    -0.06   0.950    -358.2394    335.9425
     t_2036_2037 |   1826.033    285.021     6.41   0.000     1267.402    2384.664
     t_2036_2038 |   2219.293   294.9304     7.52   0.000      1641.24    2797.346
     t_2036_2039 |   2630.665   284.4825     9.25   0.000      2073.09    3188.241
     t_2036_2040 |   3015.125   402.2712     7.50   0.000     2226.687    3803.562
    ------------------------------------------------------------------------------
    Control: Never Treated
    
    See Callaway and Sant'Anna (2021) for details
    It looks to me that the gvar option for the csdid command act similarly to the cohortvar option fort the xthdidregress command. The gvar() option is used to specify the cohort variable.

    Comment


    • #3
      Hwanseong: It appears you have exit from treatment, potentially along with staggered entry. I know how this can be done using regression methods, but I don't believe xthdidregress or csdid support treatment patters with exit. Is the first treatment always in 2015 and the last always in 2020, or does that vary by firm?

      Comment


      • #4
        Jeff Wooldridge
        The first treatment and second always start at the same year(2015, 2018) for all firms.
        I would appreciate it if you could explain or provide a link to the regression methods.
        For now, I am using xthdidregress after removing the firms that exit the policy.
        I am getting statisticall significant results with implications for the first group that was treated in 2015 but not for the group that was treated in 2018.
        I am assuming this is because the group that was first treated in 2018 has a small sample size 80 compared to the 2015 group (1210) and never treated group (2238).
        Could you please tell me if my current method and assumption are appropriate? If not, I will try the regression methods.

        Comment


        • #5
          I'm still not sure about the setup. It seems this is a staggered intervention, where some units are subjected to the treatment in 2015, and a different set is first treated in 2018. Is this correct? Are there two different treatments or two different intervention dates? Also, your simple example -- which you need to expand on -- shows exit from the treatment after 2020.

          Comment

          Working...
          X