Announcement

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

  • How to calculate a margins plot for a DiD model when faced with colinearity issues?


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input long group int week_id float(outcome start_treatment) byte treatment float Start_TreatmentxTreatment
    43018  1           0 0 1 0
    43018  2           0 0 1 0
    43018  3           0 0 1 0
    43018  4           0 0 1 0
    43018  5           0 0 1 0
    43018  6           0 0 1 0
    43018  7           0 0 1 0
    43018  8           0 0 1 0
    43018  9           0 0 1 0
    43018 10           0 0 1 0
    43018 11           0 0 1 0
    43018 12           0 0 1 0
    43018 13           0 0 1 0
    43018 14 .0008872458 0 1 0
    43018 15  .001749846 0 1 0
    43018 16           0 0 1 0
    43018 17           0 0 1 0
    43018 18           0 0 1 0
    43018 19           0 0 1 0
    43018 20           0 0 1 0
    43018 21           0 0 1 0
    43018 22           0 0 1 0
    43018 23           0 0 1 0
    43018 24  .000961183 0 1 0
    43018 25           0 0 1 0
    43018 26  .001848429 0 1 0
    43018 27 .0009118916 0 1 0
    43018 28 .0008872458 0 1 0
    43018 29  .002686383 0 1 0
    43018 30  .005274184 0 1 0
    43018 31 .0008626001 0 1 0
    43018 32           0 1 1 1
    43018 33           0 1 1 1
    43018 34           0 1 1 1
    43018 35           0 1 1 1
    43018 36  .009414664 1 1 1
    43018 37           0 1 1 1
    43018 38           0 1 1 1
    43018 39           0 1 1 1
    43018 40           0 1 1 1
    43018 41           0 1 1 1
    43018 42           0 1 1 1
    43018 43           0 1 1 1
    43018 44 .0015280345 1 1 1
    43018 45           0 1 1 1
    43018 46 .0014540973 1 1 1
    43018 47 .0007147258 1 1 1
    43018 48 .0006900801 1 1 1
    43018 49 .0014540973 1 1 1
    43018 50           0 1 1 1
    43018 51           0 1 1 1
    43018 52           0 1 1 1
    43043  1           0 0 0 0
    43043  2           0 0 0 0
    43043  3           0 0 0 0
    43043  4           0 0 0 0
    43043  5           0 0 0 0
    43043  6           0 0 0 0
    43043  7           0 0 0 0
    43043  8           0 0 0 0
    43043  9           0 0 0 0
    43043 10           0 0 0 0
    43043 11           0 0 0 0
    43043 12   .00118411 0 0 0
    43043 13           0 0 0 0
    43043 14           0 0 0 0
    43043 15           0 0 0 0
    43043 16           0 0 0 0
    43043 17           0 0 0 0
    43043 18           0 0 0 0
    43043 19  .011077158 0 0 0
    43043 20           0 0 0 0
    43043 21           0 0 0 0
    43043 22           0 0 0 0
    43043 23           0 0 0 0
    43043 24 .0012987013 0 0 0
    43043 25 .0012987013 0 0 0
    43043 26  .005194805 0 0 0
    43043 27           0 0 0 0
    43043 28           0 0 0 0
    43043 29           0 0 0 0
    43043 30  .003590527 0 0 0
    43043 31  .003705118 0 0 0
    43043 32           0 1 0 0
    43043 33           0 1 0 0
    43043 34  .002330023 1 0 0
    43043 35  .002330023 1 0 0
    43043 36           0 1 0 0
    43043 37           0 1 0 0
    43043 38           0 1 0 0
    43043 39           0 1 0 0
    43043 40 .0022154315 1 0 0
    43043 41           0 1 0 0
    43043 42 .0021772345 1 0 0
    43043 43           0 1 0 0
    43043 44           0 1 0 0
    43043 45           0 1 0 0
    43043 46           0 1 0 0
    43043 47           0 1 0 0
    43043 48           0 1 0 0
    43043 49           0 1 0 0
    43043 50           0 1 0 0
    43043 51           0 1 0 0
    43043 52           0 1 0 0
    43075  1           0 0 1 0
    43075  2           0 0 1 0
    43075  3           0 0 1 0
    43075  4           0 0 1 0
    43075  5           0 0 1 0
    43075  6           0 0 1 0
    43075  7           0 0 1 0
    43075  8           0 0 1 0
    43075  9           0 0 1 0
    43075 10           0 0 1 0
    43075 11           0 0 1 0
    43075 12           0 0 1 0
    43075 13           0 0 1 0
    43075 14           0 0 1 0
    43075 15           0 0 1 0
    43075 16           0 0 1 0
    43075 17           0 0 1 0
    43075 18           0 0 1 0
    43075 19           0 0 1 0
    43075 20           0 0 1 0
    43075 21           0 0 1 0
    43075 22           0 0 1 0
    43075 23           0 0 1 0
    43075 24           0 0 1 0
    43075 25           0 0 1 0
    43075 26           0 0 1 0
    43075 27           0 0 1 0
    43075 28           0 0 1 0
    43075 29           0 0 1 0
    43075 30           0 0 1 0
    43075 31           0 0 1 0
    43075 32           0 1 1 1
    43075 33           0 1 1 1
    43075 34           0 1 1 1
    43075 35           0 1 1 1
    43075 36           0 1 1 1
    43075 37           0 1 1 1
    43075 38           0 1 1 1
    43075 39           0 1 1 1
    43075 40           0 1 1 1
    43075 41           0 1 1 1
    43075 42           0 1 1 1
    43075 43           0 1 1 1
    43075 44           0 1 1 1
    43075 45           0 1 1 1
    43075 46           0 1 1 1
    43075 47           0 1 1 1
    43075 48           0 1 1 1
    43075 49           0 1 1 1
    43075 50           0 1 1 1
    43075 51           0 1 1 1
    43075 52           0 1 1 1
    43081  1           0 0 1 0
    43081  2           0 0 1 0
    43081  3           0 0 1 0
    43081  4           0 0 1 0
    43081  5           0 0 1 0
    43081  6           0 0 1 0
    43081  7           0 0 1 0
    43081  8           0 0 1 0
    43081  9           0 0 1 0
    43081 10           0 0 1 0
    43081 11           0 0 1 0
    43081 12           0 0 1 0
    43081 13           0 0 1 0
    43081 14           0 0 1 0
    43081 15           0 0 1 0
    43081 16           0 0 1 0
    43081 17           0 0 1 0
    43081 18           0 0 1 0
    43081 19           0 0 1 0
    43081 20           0 0 1 0
    43081 21           0 0 1 0
    43081 22           0 0 1 0
    43081 23           0 0 1 0
    43081 24           0 0 1 0
    43081 25           0 0 1 0
    43081 26           0 0 1 0
    43081 27 .0030801494 0 1 0
    43081 28  .006094764 0 1 0
    43081 29           0 0 1 0
    43081 30           0 0 1 0
    43081 31           0 0 1 0
    43081 32           0 1 1 1
    43081 33           0 1 1 1
    43081 34           0 1 1 1
    43081 35           0 1 1 1
    43081 36           0 1 1 1
    43081 37           0 1 1 1
    43081 38           0 1 1 1
    43081 39           0 1 1 1
    43081 40           0 1 1 1
    43081 41           0 1 1 1
    43081 42           0 1 1 1
    43081 43           0 1 1 1
    43081 44           0 1 1 1
    43081 45           0 1 1 1
    43081 46           0 1 1 1
    43081 47           0 1 1 1
    43081 48           0 1 1 1
    43081 49           0 1 1 1
    43081 50           0 1 1 1
    43081 51           0 1 1 1
    43081 52           0 1 1 1
    end

    Hello. This is a manipulated version of a small chunk of a dataset I have been working with. This dataset contains 52 observations for each group in reality.
    Treatment is a dummy indicating whether a member of group was randomly selected to receive a treatment.

    Start_treatment indicates the start of the treatment period, which occurs during the same week_id for each group member.

    Start_TreatmentxTreatment is equivelant to treatment*start_treatment. It is a 1 for group members that received the treatment after the start of treatment, but not before, and a 0 for everyone else.

    Don't worry about the fact that there are a lot of 0s in the outcome. The actual dataset contains many observations. Some groups have more 0s than others.

    I have created a difference in difference model for this dataset, and I have been asked to create margins plots for it. Here is the code I have been using for the DiD model and the margins plots:

    The DiD model can either be modeled as:
    1.
    Code:
    xtreg outcome i.treatment i.start_treatment i.week_id i.treatmentt#start_treatment, fe cluster(group)
    or as

    2.
    Code:
    xtreg outcome Start_TreatmentxTreatment i.treatment i.start_treatment i.week_id, fe cluster(group)
    Panel data settings are: xtset group week_id.

    What I would like to do is create a margins predicted outcome means plot that shows the treatment and control group both before and after the treatment for both. The problem is that due to the collinearity problems that arise with the treatment dummy being 1 for every observation of certain groups, and the start of treatment being the same for every group, I am not able to calculate margins in a way that allows for proper estimation of margins for the treatment group in the pre-treatment period.

    When I try to run:
    Code:
     xtreg outcome i.treatment i.start_treatment i.week_id i.treatmentt#start_treatment, fe cluster(zip)
    margins treatment#start_treatment at(week_id=(1(1)52))
    on DiD model 1 Stata estimates none of the margins, I believe due to collinearity. I have tried setting the treatment dummy to 0 for all observations in either the first week, last week, or other weeks. The regression coefficients and margin predictions vary somewhat based on what week I select to remove when I compare them with a to a reference set of margins calculations done on a dataset that has not been altered to remove collinearity. Some weeks match up pretty well, but others don't, and the resulting plots differ too much to be usable. Here is code to create the reference margin calculations I compare the margin calculations of the "anti-collinearity" (sorry) manipulated datasets to. This code works for DiD model 2:

    Code:
     xtreg outcome Start_TreatmentxTreatment i.treatment i.start_treatment i.week_id, fe cluster(zip)[
     margins Start_TreatmentxTreatmentt#start_treatment, at(week_id=(1(1)52))
    This code seems to calculate correct margins for three out of four groups (though really, I'm not sure), the non-treated pre-treatment period group (Start_TreatmentxTreatment=0, start_treatment=0), both the treated, and both the treated, and control post treatment groups (Start_TreatmentxTreatment=1, start_treatment=1 and (Start_TreatmentxTreatment=0, start_treatment=1). But the bizarre thing is that Stata also calculates margins where (Start_TreatmentxTreatment=1, start_treatment=0). But there are no observations in my dataset where this is the case, so I'm assuming something is going on "under the hood" that gives incorrect estimates for this level.

    I have to imagine there is some standard solution to this problem that allows for calculating margins plots for DiD models for both the treatment, and control, in both the before and after treatment period, even when collinearity is present. My dataset is not unusual and I don't know how people have been creating margins plots for DiD models over the years without running into this exact same problem.

    I would greatly appreciate any assistance. Please let me know if you need me to answer clarifying questions. I am new to this level of statistical work, and I'm writing this late on a Friday night so I apologize for any lack of clarity or technical ambiguities.
    Last edited by Kyle Huisman; 17 Feb 2023, 17:59.

  • #2
    Your post has gone unanswered for a while now. I think that is partly because it is unclear exactly what you want to get out of -margins-.

    Suffice it to say that the use of -margins- is simply not possible after using -xtreg, fe- to estimate a classical DID model. The reason is colinearity, as you have (partly) noticed. The colinearity is actually more pervasive than you describe, because in addition to the variable treatment being colinear with i.group, the start_treatment variable is also colinear with the i.week_id indicators. Consequently, the effects of the variables treatment and start_treatment are unidentifiable in this kind of model. While Stata attempts to identify the model by dropping something (omitting either start_treatment or an additional i.group fixed effect, and either omitting start_treatment or an additional i.week_id indicator) and produce results, the coefficients of those variables that were originally involved in the colinearity are not valid. They are just artifacts of what Stata happened to chose to break the colinearity. In fact, mathematically, it can be proved that it is possible to find some constraint that will break the colinearity and produce any possible value of one such coefficient. Those numbers are completely meaningless: only differences among them are meaningful. And that is why you cannot use -margins- after these regressions. There is no way to code around this problem: it is linear algebra.

    There are two ways that you can avoid this problem:

    1. Give up fixed effects. Just run -regress outcome i.treatment##i.start_treatment-. This will give you a valid DID estimate of the treatment effect. You can also run -margins- after this one and you will be able to get the expected value of outcome in both groups during both time periods.

    2. Give up the classic DID model and use generalized DID. This means forgetting about the treatment and start_treatment variables altogether and using the variable you have called Start_TreatmentxTreatment. This means running -xtreg outcome i.Start_TreatmentxTreatment i.week_id, fe-. You retain the fixed effects for both group and time. And you also get a generalized DID estimate of the treatment effect from it. And you can run -margins- afterward and get estimates of the expected outcomes in those who are actively receiving treatment and in those who are not. Those margins may or may not be of interest to you. I'm not really sure what you want.

    But those are the only -margins- compatible approaches. I have run these, along with the unsuccessful approaches using classical DID in combination with fixed effects, and I show the results here:
    Code:
    . regress outcome i.treatment##i.start_treatment
    
          Source |       SS           df       MS      Number of obs   =       208
    -------------+----------------------------------   F(3, 204)       =      1.96
           Model |  .000010145         3  3.3817e-06   Prob > F        =    0.1207
        Residual |   .00035142       204  1.7226e-06   R-squared       =    0.0281
    -------------+----------------------------------   Adj R-squared   =    0.0138
           Total |  .000361566       207  1.7467e-06   Root MSE        =    .00131
    
    -------------------------------------------------------------------------------------------
                      outcome | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
    --------------------------+----------------------------------------------------------------
                  1.treatment |  -.0006108   .0002722    -2.24   0.026    -.0011475   -.0000741
            1.start_treatment |  -.0004511   .0003709    -1.22   0.225    -.0011825    .0002802
                              |
    treatment#start_treatment |
                         1 1  |   .0004219   .0004283     0.98   0.326    -.0004227    .0012664
                              |
                        _cons |   .0008822   .0002357     3.74   0.000     .0004174     .001347
    -------------------------------------------------------------------------------------------
    
    . estimates store regress
    
    . margins treatment#start_treatment
    
    Adjusted predictions                                       Number of obs = 208
    Model VCE: OLS
    
    Expression: Linear prediction, predict()
    
    -------------------------------------------------------------------------------------------
                              |            Delta-method
                              |     Margin   std. err.      t    P>|t|     [95% conf. interval]
    --------------------------+----------------------------------------------------------------
    treatment#start_treatment |
                         0 0  |   .0008822   .0002357     3.74   0.000     .0004174     .001347
                         0 1  |   .0004311   .0002864     1.51   0.134    -.0001336    .0009958
                         1 0  |   .0002714   .0001361     1.99   0.047     3.10e-06    .0005398
                         1 1  |   .0002422   .0001654     1.46   0.145    -.0000839    .0005682
    -------------------------------------------------------------------------------------------
    
    .
    . xtset group week_id
    
    Panel variable: group (strongly balanced)
     Time variable: week_id, 1 to 52
             Delta: 1 unit
    
    . xtreg outcome i.treatment##i.start_treatment, fe
    note: 1.treatment omitted because of collinearity.
    
    Fixed-effects (within) regression               Number of obs     =        208
    Group variable: group                           Number of groups  =          4
    
    R-squared:                                      Obs per group:
         Within  = 0.0075                                         min =         52
         Between = 0.4313                                         avg =       52.0
         Overall = 0.0001                                         max =         52
    
                                                    F(2,202)          =       0.76
    corr(u_i, Xb) = -0.4253                         Prob > F          =     0.4675
    
    -------------------------------------------------------------------------------------------
                      outcome | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
    --------------------------+----------------------------------------------------------------
                  1.treatment |          0  (omitted)
            1.start_treatment |  -.0004511   .0003674    -1.23   0.221    -.0011757    .0002734
                              |
    treatment#start_treatment |
                         1 1  |   .0004219   .0004243     0.99   0.321    -.0004147    .0012585
                              |
                        _cons |   .0004241   .0001168     3.63   0.000     .0001939    .0006544
    --------------------------+----------------------------------------------------------------
                      sigma_u |  .00039649
                      sigma_e |  .00130013
                          rho |  .08508947   (fraction of variance due to u_i)
    -------------------------------------------------------------------------------------------
    F test that all u_i=0: F(3, 202) = 3.68                      Prob > F = 0.0130
    
    . estimates store group_fe
    
    . margins treatment#start_treatment
    
    Adjusted predictions                                       Number of obs = 208
    Model VCE: Conventional
    
    Expression: Linear prediction, predict()
    
    -------------------------------------------------------------------------------------------
                              |            Delta-method
                              |     Margin   std. err.      z    P>|z|     [95% conf. interval]
    --------------------------+----------------------------------------------------------------
    treatment#start_treatment |
                         0 0  |          .  (not estimable)
                         0 1  |          .  (not estimable)
                         1 0  |          .  (not estimable)
                         1 1  |          .  (not estimable)
    -------------------------------------------------------------------------------------------
    
    .
    . xtreg outcome i.week_id i.treatment##i.start_treatment, fe
    note: 1.treatment omitted because of collinearity.
    note: 1.start_treatment omitted because of collinearity.
    
    Fixed-effects (within) regression               Number of obs     =        208
    Group variable: group                           Number of groups  =          4
    
    R-squared:                                      Obs per group:
         Within  = 0.2655                                         min =         52
         Between = 0.4313                                         avg =       52.0
         Overall = 0.2338                                         max =         52
    
                                                    F(52,152)         =       1.06
    corr(u_i, Xb) = -0.0852                         Prob > F          =     0.3898
    
    -------------------------------------------------------------------------------------------
                      outcome | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
    --------------------------+----------------------------------------------------------------
                      week_id |
                           2  |   4.15e-18   .0009117     0.00   1.000    -.0018013    .0018013
    ...
                          52  |  -.0003164   .0009648    -0.33   0.743    -.0022225    .0015897
                              |
                  1.treatment |          0  (omitted)
            1.start_treatment |          0  (omitted)
                              |
    treatment#start_treatment |
                         1 1  |   .0004219   .0004208     1.00   0.318    -.0004095    .0012532
                              |
                        _cons |  -4.07e-18   .0006447    -0.00   1.000    -.0012737    .0012737
    --------------------------+----------------------------------------------------------------
                      sigma_u |  .00039649
                      sigma_e |  .00128935
                          rho |  .08639446   (fraction of variance due to u_i)
    -------------------------------------------------------------------------------------------
    F test that all u_i=0: F(3, 152) = 3.74                      Prob > F = 0.0125
    
    . estimates store group_week_fe
    
    . margins treatment#start_treatment
    
    Predictive margins                                         Number of obs = 208
    Model VCE: Conventional
    
    Expression: Linear prediction, predict()
    
    -------------------------------------------------------------------------------------------
                              |            Delta-method
                              |     Margin   std. err.      z    P>|z|     [95% conf. interval]
    --------------------------+----------------------------------------------------------------
    treatment#start_treatment |
                         0 0  |          .  (not estimable)
                         0 1  |          .  (not estimable)
                         1 0  |          .  (not estimable)
                         1 1  |          .  (not estimable)
    -------------------------------------------------------------------------------------------
    
    .
    . xtreg outcome i.Start_TreatmentxTreatment i.week_id, fe
    
    Fixed-effects (within) regression               Number of obs     =        208
    Group variable: group                           Number of groups  =          4
    
    R-squared:                                      Obs per group:
         Within  = 0.2655                                         min =         52
         Between = 0.4313                                         avg =       52.0
         Overall = 0.2338                                         max =         52
    
                                                    F(52,152)         =       1.06
    corr(u_i, Xb) = -0.0852                         Prob > F          =     0.3898
    
    ---------------------------------------------------------------------------------------------
                        outcome | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
    ----------------------------+----------------------------------------------------------------
    1.Start_TreatmentxTreatment |   .0004219   .0004208     1.00   0.318    -.0004095    .0012532
                                |
                        week_id |
                             2  |   3.57e-18   .0009117     0.00   1.000    -.0018013    .0018013
    ...
                            52  |  -.0003164   .0009648    -0.33   0.743    -.0022225    .0015897
                                |
                          _cons |  -3.47e-18   .0006447    -0.00   1.000    -.0012737    .0012737
    ----------------------------+----------------------------------------------------------------
                        sigma_u |  .00039649
                        sigma_e |  .00128935
                            rho |  .08639446   (fraction of variance due to u_i)
    ---------------------------------------------------------------------------------------------
    F test that all u_i=0: F(3, 152) = 3.74                      Prob > F = 0.0125
    
    . estimates store generalized_did
    
    . margins Start_TreatmentxTreatment
    
    Predictive margins                                         Number of obs = 208
    Model VCE: Conventional
    
    Expression: Linear prediction, predict()
    
    -------------------------------------------------------------------------------------------
                              |            Delta-method
                              |     Margin   std. err.      z    P>|z|     [95% conf. interval]
    --------------------------+----------------------------------------------------------------
    Start_TreatmentxTreatment |
                           0  |   .0002419   .0001557     1.55   0.120    -.0000632    .0005471
                           1  |   .0006638   .0003067     2.16   0.030     .0000628    .0012648
    -------------------------------------------------------------------------------------------
    
    .
    . esttab regress group_fe group_week_fe generalized_did
    
    ----------------------------------------------------------------------------
                          (1)             (2)             (3)             (4)  
                      outcome         outcome         outcome         outcome  
    ----------------------------------------------------------------------------
    0.treatment             0               0               0                  
                          (.)             (.)             (.)                  
    
    1.treatment     -0.000611*              0               0                  
                      (-2.24)             (.)             (.)                  
    
    0.start_tr~t            0               0               0                  
                          (.)             (.)             (.)                  
    
    1.start_tr~t    -0.000451       -0.000451               0                  
                      (-1.22)         (-1.23)             (.)                  
    
    0.treatmen~t            0               0               0                  
                          (.)             (.)             (.)                  
    
    0.treatmen~t            0               0               0                  
                          (.)             (.)             (.)                  
    
    1.treatmen~t            0               0               0                  
                          (.)             (.)             (.)                  
    
    1.treatmen~t     0.000422        0.000422        0.000422                  
                       (0.98)          (0.99)          (1.00)                   
    
    1.week_id                                               0               0  
                                                          (.)             (.)  
    
    2.week_id                                        4.15e-18        3.57e-18  
                                                       (0.00)          (0.00)  
    
    3.week_id                                        4.17e-18        3.52e-18  
                                                       (0.00)          (0.00)  
    
    4.week_id                                        4.17e-18        3.49e-18  
                                                       (0.00)          (0.00)  
    
    5.week_id                                        4.16e-18        3.54e-18  
                                                       (0.00)          (0.00)  
    
    6.week_id                                        4.17e-18        3.49e-18  
                                                       (0.00)          (0.00)  
    
    7.week_id                                        4.17e-18        3.51e-18  
                                                       (0.00)          (0.00)  
    
    8.week_id                                        4.17e-18        3.54e-18  
                                                       (0.00)          (0.00)  
    
    9.week_id                                        4.11e-18        3.56e-18  
                                                       (0.00)          (0.00)  
    
    10.week_id                                       4.12e-18        3.56e-18  
                                                       (0.00)          (0.00)  
    
    11.week_id                                       4.09e-18        3.51e-18  
                                                       (0.00)          (0.00)  
    
    12.week_id                                       0.000296        0.000296  
                                                       (0.32)          (0.32)  
    
    13.week_id                                       4.14e-18        3.51e-18  
                                                       (0.00)          (0.00)  
    
    14.week_id                                       0.000222        0.000222  
                                                       (0.24)          (0.24)  
    
    15.week_id                                       0.000437        0.000437  
                                                       (0.48)          (0.48)  
    
    16.week_id                                       4.16e-18        3.57e-18  
                                                       (0.00)          (0.00)  
    
    17.week_id                                       4.13e-18        3.59e-18  
                                                       (0.00)          (0.00)  
    
    18.week_id                                       4.19e-18        3.54e-18  
                                                       (0.00)          (0.00)  
    
    19.week_id                                        0.00277**       0.00277**
                                                       (3.04)          (3.04)  
    
    20.week_id                                       4.19e-18        3.59e-18  
                                                       (0.00)          (0.00)  
    
    21.week_id                                       4.11e-18        3.61e-18  
                                                       (0.00)          (0.00)  
    
    22.week_id                                       4.12e-18        3.64e-18  
                                                       (0.00)          (0.00)  
    
    23.week_id                                       4.17e-18        3.50e-18  
                                                       (0.00)          (0.00)  
    
    24.week_id                                       0.000565        0.000565  
                                                       (0.62)          (0.62)  
    
    25.week_id                                       0.000325        0.000325  
                                                       (0.36)          (0.36)  
    
    26.week_id                                        0.00176         0.00176  
                                                       (1.93)          (1.93)  
    
    27.week_id                                       0.000998        0.000998  
                                                       (1.09)          (1.09)  
    
    28.week_id                                        0.00175         0.00175  
                                                       (1.91)          (1.91)  
    
    29.week_id                                       0.000672        0.000672  
                                                       (0.74)          (0.74)  
    
    30.week_id                                        0.00222*        0.00222*  
                                                       (2.43)          (2.43)  
    
    31.week_id                                        0.00114         0.00114  
                                                       (1.25)          (1.25)  
    
    32.week_id                                      -0.000316       -0.000316  
                                                      (-0.33)         (-0.33)  
    
    33.week_id                                      -0.000316       -0.000316  
                                                      (-0.33)         (-0.33)  
    
    34.week_id                                       0.000266        0.000266  
                                                       (0.28)          (0.28)  
    
    35.week_id                                       0.000266        0.000266  
                                                       (0.28)          (0.28)  
    
    36.week_id                                        0.00204*        0.00204*  
                                                       (2.11)          (2.11)  
    
    37.week_id                                      -0.000316       -0.000316  
                                                      (-0.33)         (-0.33)  
    
    38.week_id                                      -0.000316       -0.000316  
                                                      (-0.33)         (-0.33)  
    
    39.week_id                                      -0.000316       -0.000316  
                                                      (-0.33)         (-0.33)  
    
    40.week_id                                       0.000237        0.000237  
                                                       (0.25)          (0.25)  
    
    41.week_id                                      -0.000316       -0.000316  
                                                      (-0.33)         (-0.33)  
    
    42.week_id                                       0.000228        0.000228  
                                                       (0.24)          (0.24)  
    
    43.week_id                                      -0.000316       -0.000316  
                                                      (-0.33)         (-0.33)  
    
    44.week_id                                      0.0000656       0.0000656  
                                                       (0.07)          (0.07)  
    
    45.week_id                                      -0.000316       -0.000316  
                                                      (-0.33)         (-0.33)  
    
    46.week_id                                      0.0000471       0.0000471  
                                                       (0.05)          (0.05)  
    
    47.week_id                                      -0.000138       -0.000138  
                                                      (-0.14)         (-0.14)  
    
    48.week_id                                      -0.000144       -0.000144  
                                                      (-0.15)         (-0.15)  
    
    49.week_id                                      0.0000471       0.0000471  
                                                       (0.05)          (0.05)  
    
    50.week_id                                      -0.000316       -0.000316  
                                                      (-0.33)         (-0.33)  
    
    51.week_id                                      -0.000316       -0.000316  
                                                      (-0.33)         (-0.33)  
    
    52.week_id                                      -0.000316       -0.000316  
                                                      (-0.33)         (-0.33)  
    
    0.Start_Tr~t                                                            0  
                                                                          (.)  
    
    1.Start_Tr~t                                                     0.000422  
                                                                       (1.00)   
    
    _cons            0.000882***     0.000424***    -4.07e-18       -3.47e-18  
                       (3.74)          (3.63)         (-0.00)         (-0.00)  
    ----------------------------------------------------------------------------
    N                     208             208             208             208  
    ----------------------------------------------------------------------------
    t statistics in parentheses
    * p<0.05, ** p<0.01, *** p<0.001
    
    .
    end of do-file
    Note: -xtreg- output for i.week_id indicators has been mostly elided to keep this post within the Forum's character count limit.

    Notice that the DID estimates (shown in red) come out approximately the same in all four models. In fact, given that all of your treated groups begin treatment at the same time, if your data were balanced, these estimates would be exactly equal.

    So, you need to think about what exactly you were hoping to get from -margins-. Perhaps one of the two -margins-supporting models' results are what you were looking for. If not, you are chasing an impossibility--back to the drawing boards!
    Last edited by Clyde Schechter; 18 Feb 2023, 14:53.

    Comment


    • #3
      Thanks so much for your through response, Clyde. I had a slight suspicion that what I was trying to do was impossible, but for some reason it did not occur to me that the start of the treatment was colinear with the i.week_id. I should have thought the problem through more carefully at the outset. However, both of the alternatives you outlined in your post can fulfill the same purpose (to serve as a visual aid in a presentation) I was hoping to accomplish by creating plots that defy the rules of algebra. The first option that just uses regress is nice because it allows for comparison between the two groups, but because the fixed effects are important in this model I think I will use the second visualization.

      Regardless, your response resolves my question. Thanks again for taking the time to look at this.

      Kyle

      Comment


      • #4
        x
        Last edited by Kyle Huisman; 19 Feb 2023, 16:13.

        Comment

        Working...
        X