Announcement

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

  • Time trend vs dummy variables in panel models: perfect collinearity issue

    Hi,

    I am attempting the estimate of the effect of 3 different drugs on various patient outcomes.

    I am estimating a simple panel fixed effects model using xtreg, fe.

    My dataset includes three time points and around 300 patients (around 900 observations in total). At baseline all patients do not take any drug, while at both time 1 (after 3 months) and time 2 (after 6 months) some patients take drug 1, others drug 2, and the remaining patients take drug 3. Patients taking a drug (e.g. drug 1) cannot also take other drugs (e.g. drug 2 and 3). So I generate three (mutually exclusive) drug dummies.

    When I run my panel data model using the fixed-effects estimator (xtreg, fe), in addition to the three drug dummies (and some other time-varying controls) I also include time dummies for time 1 and time 2 (so that the reference category is the baseline time dummy). However, the time 2 dummy is dropped because the sum of time 1 dummy and time 2 dummy is collinear with the sum of the three drug dummies.

    Since, for obvious reasons, I need to keep all three drug dummies in my specification I tried using a time trend instead of the two time dummies also allowing for a non-linear time trend (i.e. squared time trend). This specification is estimated succesfully but I would like to ask you whether this makes any sense to you.

    Shouldn't the time trend variable be dropped for the same reason the time 2 dummy is dropped, i.e. perfect collinearity?

    Thanks,
    Lukas
    Last edited by Lukas Lang; 06 Jul 2018, 12:07.
    ------
    I use Stata 17

  • #2
    The sum of the three treatment indicators ("dummies") is always 1, by construction. So even in the absence of fixed effects, one of them would have to be omitted. The presence of fixed effects at the patient level introduces a different colinearity. In this case, the value of all of the treatment indicators is constant within any person, so that each of the treatment indicators would equal the sum of the fixed effects for those patients who were assigned to that treatment group. Consequently all three treatment indicators would be omitted here. These treatment effects cannot be estimated in a fixed effects model in this way.

    From your description of the treatment of time, I get the impression that there is something wrong with your data, or you have constructed the time indicators incorrectly. You have three time periods and two time indicators. This is correct. The sum of the two time indicators will not be constantly 1 (which is the sum of the treatment indicators), because in observations for the baseline period, the two time indicators will both be zero. Now will the time indicators be colinear with the fixed effects because each participant (or nearly all of them) has observations in each of the three time periods. So with correct data and indicators, the introduction of these time indicators should not be a problem at all. And I am having difficulty imagining a situation in which replacing the two time indicators by time and time squared would resolve a colinearity problem.

    I think that for more specific advice, you need to show an example of your data. Please load in your data set, and identify a reasonable sized subsample of the data that replicates this problem. Then run the -dataex- command and paste that output here. If you are running version 15.1 or a fully updated version 14.2, it is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    As an aside, it seems to me that you have, in any case, not chosen an analysis suitable for your research goals. Your study design is best suited to estimating the effects of the three drug treatments using a difference-in-differences approach for this longitudinal analysis. Basically your analysis should look something like this:

    Code:
    xtreg outcome i.drug##i.time perhaps_some_covariates, fe
    margins drug, dydx(time)
    margins drug, dydx(time) pwcompare
    were drug is a single variable encoding the treatments as 1, 2, and 3, and time is a single variable encoding the times as 0 (baseline), 1, and 2.

    Comment


    • #3
      Hi Clyde,

      Thank you a lot for your hints about how to better present the problem and for your thouhgts about the correct specification.

      Please find below an extract of the dataset. I tried to simplify the dataset by including the variables of key interest only.

      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input float(id t) double outcome float(nodrug drug1 drug2 drug3 drug) byte(t_1 t_2 t_3) float(trend trend2)
       1 0  .716 1 0 0 0 0 1 0 0 1 1
       1 1  .653 0 1 0 0 1 0 1 0 2 4
       1 2  .668 0 1 0 0 1 0 0 1 3 9
       2 0  .624 1 0 0 0 0 1 0 0 1 1
       2 1  .671 0 1 0 0 1 0 1 0 2 4
       2 2  .669 0 1 0 0 1 0 0 1 3 9
       3 0  .426 1 0 0 0 0 1 0 0 1 1
       3 1  .651 0 1 0 0 1 0 1 0 2 4
       3 2  .304 0 1 0 0 1 0 0 1 3 9
       4 0  .406 1 0 0 0 0 1 0 0 1 1
       4 1  .419 0 1 0 0 1 0 1 0 2 4
       4 2  .596 0 1 0 0 1 0 0 1 3 9
       5 0  .555 1 0 0 0 0 1 0 0 1 1
       5 1  .703 0 1 0 0 1 0 1 0 2 4
       5 2  .755 0 1 0 0 1 0 0 1 3 9
       6 0  .679 1 0 0 0 0 1 0 0 1 1
       6 1  .795 0 1 0 0 1 0 1 0 2 4
       6 2  .689 0 1 0 0 1 0 0 1 3 9
       7 0  .309 1 0 0 0 0 1 0 0 1 1
       7 1 -.112 0 1 0 0 1 0 1 0 2 4
       7 2  .169 0 1 0 0 1 0 0 1 3 9
       8 0  .813 1 0 0 0 0 1 0 0 1 1
       8 1  .661 0 1 0 0 1 0 1 0 2 4
       8 2  .716 0 1 0 0 1 0 0 1 3 9
       9 0  .635 1 0 0 0 0 1 0 0 1 1
       9 1  .422 0 1 0 0 1 0 1 0 2 4
       9 2  .292 0 1 0 0 1 0 0 1 3 9
      10 0  .541 1 0 0 0 0 1 0 0 1 1
      10 1  .533 0 1 0 0 1 0 1 0 2 4
      10 2  .555 0 1 0 0 1 0 0 1 3 9
      11 0  .063 1 0 0 0 0 1 0 0 1 1
      11 1  .107 0 1 0 0 1 0 1 0 2 4
      11 2  .045 0 1 0 0 1 0 0 1 3 9
      12 0  .321 1 0 0 0 0 1 0 0 1 1
      12 1  .336 0 1 0 0 1 0 1 0 2 4
      12 2  .294 0 1 0 0 1 0 0 1 3 9
      13 0  .303 1 0 0 0 0 1 0 0 1 1
      13 1  .293 0 1 0 0 1 0 1 0 2 4
      13 2 -.069 0 1 0 0 1 0 0 1 3 9
      14 0  .511 1 0 0 0 0 1 0 0 1 1
      14 1  .504 0 1 0 0 1 0 1 0 2 4
      14 2   .77 0 1 0 0 1 0 0 1 3 9
      15 0  .657 1 0 0 0 0 1 0 0 1 1
      15 1  .632 0 1 0 0 1 0 1 0 2 4
      15 2  .883 0 1 0 0 1 0 0 1 3 9
      16 0   .62 1 0 0 0 0 1 0 0 1 1
      16 1  .767 0 1 0 0 1 0 1 0 2 4
      16 2  .099 0 1 0 0 1 0 0 1 3 9
      17 0  .335 1 0 0 0 0 1 0 0 1 1
      17 1   .85 0 1 0 0 1 0 1 0 2 4
      17 2  .689 0 1 0 0 1 0 0 1 3 9
      18 0  .426 1 0 0 0 0 1 0 0 1 1
      18 1  .668 0 1 0 0 1 0 1 0 2 4
      18 2  .283 0 1 0 0 1 0 0 1 3 9
      19 0  .517 1 0 0 0 0 1 0 0 1 1
      19 1  .171 0 1 0 0 1 0 1 0 2 4
      19 2  .603 0 1 0 0 1 0 0 1 3 9
      20 0  .709 1 0 0 0 0 1 0 0 1 1
      20 1  .531 0 1 0 0 1 0 1 0 2 4
      20 2  .345 0 1 0 0 1 0 0 1 3 9
      21 0  .548 1 0 0 0 0 1 0 0 1 1
      21 1   .71 0 1 0 0 1 0 1 0 2 4
      21 2  .206 0 1 0 0 1 0 0 1 3 9
      22 0  .635 1 0 0 0 0 1 0 0 1 1
      22 1  .583 0 1 0 0 1 0 1 0 2 4
      22 2  .627 0 1 0 0 1 0 0 1 3 9
      23 0  .703 1 0 0 0 0 1 0 0 1 1
      23 1  .735 0 1 0 0 1 0 1 0 2 4
      23 2  .723 0 1 0 0 1 0 0 1 3 9
      24 0  .479 1 0 0 0 0 1 0 0 1 1
      24 1  .496 0 1 0 0 1 0 1 0 2 4
      24 2   .62 0 1 0 0 1 0 0 1 3 9
      25 0 -.208 1 0 0 0 0 1 0 0 1 1
      25 1 -.353 0 1 0 0 1 0 1 0 2 4
      25 2  .602 0 1 0 0 1 0 0 1 3 9
      26 0  .598 1 0 0 0 0 1 0 0 1 1
      26 1  .635 0 1 0 0 1 0 1 0 2 4
      26 2  .494 0 1 0 0 1 0 0 1 3 9
      27 0  .836 1 0 0 0 0 1 0 0 1 1
      27 1  .826 0 1 0 0 1 0 1 0 2 4
      27 2  .392 0 1 0 0 1 0 0 1 3 9
      28 0   .32 1 0 0 0 0 1 0 0 1 1
      28 1  .099 0 1 0 0 1 0 1 0 2 4
      28 2  .081 0 1 0 0 1 0 0 1 3 9
      29 0  .575 1 0 0 0 0 1 0 0 1 1
      29 1  .487 0 1 0 0 1 0 1 0 2 4
      29 2  .836 0 1 0 0 1 0 0 1 3 9
      30 0  .906 1 0 0 0 0 1 0 0 1 1
      30 1  .906 0 1 0 0 1 0 1 0 2 4
      30 2  .826 0 1 0 0 1 0 0 1 3 9
      31 0  .689 1 0 0 0 0 1 0 0 1 1
      31 1  .735 0 1 0 0 1 0 1 0 2 4
      31 2  .491 0 1 0 0 1 0 0 1 3 9
      32 0  .826 1 0 0 0 0 1 0 0 1 1
      32 1  .877 0 1 0 0 1 0 1 0 2 4
      32 2  .777 0 1 0 0 1 0 0 1 3 9
      33 0  .768 1 0 0 0 0 1 0 0 1 1
      33 1  .837 0 1 0 0 1 0 1 0 2 4
      33 2  .837 0 1 0 0 1 0 0 1 3 9
      34 0  .645 1 0 0 0 0 1 0 0 1 1
      34 1  .627 0 0 1 0 2 0 1 0 2 4
      34 2  .632 0 0 1 0 2 0 0 1 3 9
      35 0  .883 1 0 0 0 0 1 0 0 1 1
      35 1  .836 0 0 1 0 2 0 1 0 2 4
      35 2  .814 0 0 1 0 2 0 0 1 3 9
      36 0  .716 1 0 0 0 0 1 0 0 1 1
      36 1  .691 0 0 1 0 2 0 1 0 2 4
      36 2  .393 0 0 1 0 2 0 0 1 3 9
      37 0  .451 1 0 0 0 0 1 0 0 1 1
      37 1   .42 0 0 1 0 2 0 1 0 2 4
      37 2  .706 0 0 1 0 2 0 0 1 3 9
      38 0   .61 1 0 0 0 0 1 0 0 1 1
      38 1  .555 0 0 1 0 2 0 1 0 2 4
      38 2   .56 0 0 1 0 2 0 0 1 3 9
      39 0   .08 1 0 0 0 0 1 0 0 1 1
      39 1  .491 0 0 1 0 2 0 1 0 2 4
      39 2  .515 0 0 1 0 2 0 0 1 3 9
      40 0  .494 1 0 0 0 0 1 0 0 1 1
      40 1   .62 0 0 1 0 2 0 1 0 2 4
      40 2  .466 0 0 1 0 2 0 0 1 3 9
      41 0  .516 1 0 0 0 0 1 0 0 1 1
      41 1  .516 0 0 1 0 2 0 1 0 2 4
      41 2  .378 0 0 1 0 2 0 0 1 3 9
      42 0 -.014 1 0 0 0 0 1 0 0 1 1
      42 1 -.107 0 0 1 0 2 0 1 0 2 4
      42 2  .132 0 0 1 0 2 0 0 1 3 9
      43 0  .605 1 0 0 0 0 1 0 0 1 1
      43 1  .635 0 0 1 0 2 0 1 0 2 4
      43 2  .622 0 0 1 0 2 0 0 1 3 9
      44 0  .226 1 0 0 0 0 1 0 0 1 1
      44 1  .567 0 0 1 0 2 0 1 0 2 4
      44 2  .066 0 0 1 0 2 0 0 1 3 9
      45 0  .057 1 0 0 0 0 1 0 0 1 1
      45 1   .26 0 0 1 0 2 0 1 0 2 4
      45 2  .691 0 0 1 0 2 0 0 1 3 9
      46 0  .433 1 0 0 0 0 1 0 0 1 1
      46 1   .32 0 0 1 0 2 0 1 0 2 4
      46 2  .716 0 0 1 0 2 0 0 1 3 9
      47 0  .645 1 0 0 0 0 1 0 0 1 1
      47 1  .848 0 0 1 0 2 0 1 0 2 4
      47 2  .812 0 0 1 0 2 0 0 1 3 9
      48 0  .883 1 0 0 0 0 1 0 0 1 1
      48 1  .812 0 0 1 0 2 0 1 0 2 4
      48 2  .812 0 0 1 0 2 0 0 1 3 9
      49 0  .432 1 0 0 0 0 1 0 0 1 1
      49 1  .758 0 0 1 0 2 0 1 0 2 4
      49 2  .758 0 0 1 0 2 0 0 1 3 9
      50 0  .206 1 0 0 0 0 1 0 0 1 1
      50 1  .201 0 0 1 0 2 0 1 0 2 4
      50 2 -.134 0 0 1 0 2 0 0 1 3 9
      51 0  .698 1 0 0 0 0 1 0 0 1 1
      51 1   .62 0 0 1 0 2 0 1 0 2 4
      51 2  .427 0 0 1 0 2 0 0 1 3 9
      52 0   .58 1 0 0 0 0 1 0 0 1 1
      52 1  .836 0 0 1 0 2 0 1 0 2 4
      52 2  .723 0 0 1 0 2 0 0 1 3 9
      53 0 -.042 1 0 0 0 0 1 0 0 1 1
      53 1 -.041 0 0 1 0 2 0 1 0 2 4
      53 2  .304 0 0 1 0 2 0 0 1 3 9
      54 0  .814 1 0 0 0 0 1 0 0 1 1
      54 1  .743 0 0 1 0 2 0 1 0 2 4
      54 2  .762 0 0 1 0 2 0 0 1 3 9
      55 0  .767 1 0 0 0 0 1 0 0 1 1
      55 1   .74 0 0 1 0 2 0 1 0 2 4
      55 2  .767 0 0 1 0 2 0 0 1 3 9
      56 0  .689 1 0 0 0 0 1 0 0 1 1
      56 1  .836 0 0 1 0 2 0 1 0 2 4
      56 2  .906 0 0 1 0 2 0 0 1 3 9
      57 0  .604 1 0 0 0 0 1 0 0 1 1
      57 1  .678 0 0 1 0 2 0 1 0 2 4
      57 2  .654 0 0 1 0 2 0 0 1 3 9
      58 0  .639 1 0 0 0 0 1 0 0 1 1
      58 1  .806 0 0 1 0 2 0 1 0 2 4
      58 2    .6 0 0 1 0 2 0 0 1 3 9
      59 0  .627 1 0 0 0 0 1 0 0 1 1
      59 1  .531 0 0 1 0 2 0 1 0 2 4
      59 2   .71 0 0 1 0 2 0 0 1 3 9
      60 0  .635 1 0 0 0 0 1 0 0 1 1
      60 1  .321 0 0 1 0 2 0 1 0 2 4
      60 2  .335 0 0 1 0 2 0 0 1 3 9
      61 0  .185 1 0 0 0 0 1 0 0 1 1
      61 1  .678 0 0 1 0 2 0 1 0 2 4
      61 2  .686 0 0 1 0 2 0 0 1 3 9
      62 0  .727 1 0 0 0 0 1 0 0 1 1
      62 1  .555 0 0 1 0 2 0 1 0 2 4
      62 2  .511 0 0 1 0 2 0 0 1 3 9
      63 0  .587 1 0 0 0 0 1 0 0 1 1
      63 1  .648 0 0 1 0 2 0 1 0 2 4
      63 2  .698 0 0 1 0 2 0 0 1 3 9
      64 0  .778 1 0 0 0 0 1 0 0 1 1
      64 1  .836 0 0 1 0 2 0 1 0 2 4
      64 2  .778 0 0 1 0 2 0 0 1 3 9
      65 0  .393 1 0 0 0 0 1 0 0 1 1
      65 1  .246 0 0 1 0 2 0 1 0 2 4
      65 2  .221 0 0 1 0 2 0 0 1 3 9
      66 0  .906 1 0 0 0 0 1 0 0 1 1
      66 1  .765 0 0 1 0 2 0 1 0 2 4
      66 2  .837 0 0 1 0 2 0 0 1 3 9
      67 0  .698 1 0 0 0 0 1 0 0 1 1
      67 1  .812 0 0 1 0 2 0 1 0 2 4
      67 2  .743 0 0 1 0 2 0 0 1 3 9
      68 0 -.427 1 0 0 0 0 1 0 0 1 1
      68 1  -.51 0 0 0 1 3 0 1 0 2 4
      68 2 -.594 0 0 0 1 3 0 0 1 3 9
      69 0  .558 1 0 0 0 0 1 0 0 1 1
      69 1  .546 0 0 0 1 3 0 1 0 2 4
      69 2  .344 0 0 0 1 3 0 0 1 3 9
      70 0  .622 1 0 0 0 0 1 0 0 1 1
      70 1  .743 0 0 0 1 3 0 1 0 2 4
      70 2  .607 0 0 0 1 3 0 0 1 3 9
      71 0  .045 1 0 0 0 0 1 0 0 1 1
      71 1  .291 0 0 0 1 3 0 1 0 2 4
      71 2  .338 0 0 0 1 3 0 0 1 3 9
      72 0  .906 1 0 0 0 0 1 0 0 1 1
      72 1  .906 0 0 0 1 3 0 1 0 2 4
      72 2  .735 0 0 0 1 3 0 0 1 3 9
      73 0  .617 1 0 0 0 0 1 0 0 1 1
      73 1   .76 0 0 0 1 3 0 1 0 2 4
      73 2  .393 0 0 0 1 3 0 0 1 3 9
      74 0  .806 1 0 0 0 0 1 0 0 1 1
      74 1  .836 0 0 0 1 3 0 1 0 2 4
      74 2  .906 0 0 0 1 3 0 0 1 3 9
      75 0   .55 1 0 0 0 0 1 0 0 1 1
      75 1  .763 0 0 0 1 3 0 1 0 2 4
      75 2   .74 0 0 0 1 3 0 0 1 3 9
      76 0     1 1 0 0 0 0 1 0 0 1 1
      76 1     1 0 0 0 1 3 0 1 0 2 4
      76 2  .837 0 0 0 1 3 0 0 1 3 9
      77 0  .836 1 0 0 0 0 1 0 0 1 1
      77 1  .636 0 0 0 1 3 0 1 0 2 4
      77 2  .836 0 0 0 1 3 0 0 1 3 9
      78 0  .617 1 0 0 0 0 1 0 0 1 1
      78 1  .725 0 0 0 1 3 0 1 0 2 4
      78 2  .722 0 0 0 1 3 0 0 1 3 9
      79 0  .689 1 0 0 0 0 1 0 0 1 1
      79 1  .671 0 0 0 1 3 0 1 0 2 4
      79 2  .837 0 0 0 1 3 0 0 1 3 9
      80 0  .378 1 0 0 0 0 1 0 0 1 1
      80 1  .378 0 0 0 1 3 0 1 0 2 4
      80 2  .019 0 0 0 1 3 0 0 1 3 9
      81 0   .71 1 0 0 0 0 1 0 0 1 1
      81 1  .728 0 0 0 1 3 0 1 0 2 4
      81 2  .739 0 0 0 1 3 0 0 1 3 9
      82 0  .584 1 0 0 0 0 1 0 0 1 1
      82 1  .504 0 0 0 1 3 0 1 0 2 4
      82 2  .752 0 0 0 1 3 0 0 1 3 9
      83 0   .71 1 0 0 0 0 1 0 0 1 1
      83 1   .71 0 0 0 1 3 0 1 0 2 4
      83 2  .721 0 0 0 1 3 0 0 1 3 9
      84 0  .727 1 0 0 0 0 1 0 0 1 1
      84 1  .821 0 0 0 1 3 0 1 0 2 4
      84 2  .691 0 0 0 1 3 0 0 1 3 9
      85 0  .659 1 0 0 0 0 1 0 0 1 1
      85 1  .821 0 0 0 1 3 0 1 0 2 4
      85 2   .72 0 0 0 1 3 0 0 1 3 9
      86 0  .758 1 0 0 0 0 1 0 0 1 1
      86 1   .74 0 0 0 1 3 0 1 0 2 4
      86 2  .671 0 0 0 1 3 0 0 1 3 9
      87 0  .836 1 0 0 0 0 1 0 0 1 1
      87 1  .716 0 0 0 1 3 0 1 0 2 4
      87 2  .422 0 0 0 1 3 0 0 1 3 9
      88 0  .554 1 0 0 0 0 1 0 0 1 1
      88 1 -.112 0 0 0 1 3 0 1 0 2 4
      88 2  .363 0 0 0 1 3 0 0 1 3 9
      89 0  .836 1 0 0 0 0 1 0 0 1 1
      89 1  .728 0 0 0 1 3 0 1 0 2 4
      89 2  .691 0 0 0 1 3 0 0 1 3 9
      90 0 -.134 1 0 0 0 0 1 0 0 1 1
      90 1 -.268 0 0 0 1 3 0 1 0 2 4
      90 2 -.429 0 0 0 1 3 0 0 1 3 9
      91 0  .213 1 0 0 0 0 1 0 0 1 1
      91 1  .011 0 0 0 1 3 0 1 0 2 4
      91 2  .255 0 0 0 1 3 0 0 1 3 9
      92 0  .521 1 0 0 0 0 1 0 0 1 1
      92 1  .398 0 0 0 1 3 0 1 0 2 4
      92 2  .325 0 0 0 1 3 0 0 1 3 9
      93 0  .479 1 0 0 0 0 1 0 0 1 1
      93 1 -.218 0 0 0 1 3 0 1 0 2 4
      93 2   -.2 0 0 0 1 3 0 0 1 3 9
      94 0  .383 1 0 0 0 0 1 0 0 1 1
      94 1  .413 0 0 0 1 3 0 1 0 2 4
      94 2  .577 0 0 0 1 3 0 0 1 3 9
      end
      Please find below the results of the regressions of interest.

      Let me point out that, as you will also notice in the dataset, patients at baseline (t=0) do not take any drug so that the three drug dummies are equal to zero at baseline.

      In my fixed-effects regressions, when I include the three drug dummies, the time 3 dummy is dropped because of collinearity (as showed below).

      Code:
      xtset id t
      
      xtreg outcome drug1 drug2 drug3 t_2 t_3, fe
      note: t_3 omitted because of collinearity
      
      Fixed-effects (within) regression               Number of obs     =        282
      Group variable: id                              Number of groups  =         94
      
      R-sq:                                           Obs per group:
      within  = 0.0281                                         min =          3
      between = 0.0055                                         avg =        3.0
      overall = 0.0096                                         max =          3
      
      F(4,184)          =       1.33
      corr(u_i, Xb)  = -0.0270                        Prob > F          =     0.2597
      
      
      outcome       Coef.   Std. Err.      t    P>t     [95% Conf. Interval]
      
      drug1   -.0242045   .0353971    -0.68   0.495     -.094041    .0456319
      drug2    .0342059    .034928     0.98   0.329     -.034705    .1031168
      drug3   -.0705648   .0387585    -1.82   0.070    -.1470331    .0059034
      t_2       .0185   .0229139     0.81   0.420    -.0267078    .0637078
      t_3           0  (omitted)
      _cons    .5428404   .0162026    33.50   0.000     .5108737    .5748072
      
      sigma_u    .2619485
      sigma_e   .15709004
      rho   .73548993   (fraction of variance due to u_i)
      
      F test that all u_i=0: F(93, 184) = 8.33                     Prob > F = 0.0000
      The same does not happen when I use the trend variable instead of time dummies (also as showed below).

      This is what is unclear to me: why isn't the time trend variable dropped for the same collinearity reason the time 2 dummy is dropped?

      Code:
      xtreg outcome drug1 drug2 drug3 trend, fe
      
      Fixed-effects (within) regression               Number of obs     =        282
      Group variable: id                              Number of groups  =         94
      
      R-sq:                                           Obs per group:
      within  = 0.0281                                         min =          3
      between = 0.0055                                         avg =        3.0
      overall = 0.0096                                         max =          3
      
      F(4,184)          =       1.33
      corr(u_i, Xb)  = -0.0270                        Prob > F          =     0.2597
      
      
      outcome       Coef.   Std. Err.      t    P>t     [95% Conf. Interval]
      
      drug1    .0127955   .0479901     0.27   0.790    -.0818862    .1074772
      drug2    .0712059   .0476452     1.49   0.137    -.0227952     .165207
      drug3   -.0335648   .0505205    -0.66   0.507    -.1332387    .0661091
      trend      -.0185   .0229139    -0.81   0.420    -.0637078    .0267078
      _cons    .5613404   .0280637    20.00   0.000     .5059724    .6167085
      
      sigma_u    .2619485
      sigma_e   .15709004
      rho   .73548993   (fraction of variance due to u_i)
      
      F test that all u_i=0: F(93, 184) = 8.33                     Prob > F = 0.0000
      If I use your suggested DiD specficiation, I get what showed below.

      Code:
      xtreg outcome i.drug##i.t, fe
      note: 2.t omitted because of collinearity
      note: 0b.drug#1.t identifies no observations in the sample
      note: 0b.drug#2.t identifies no observations in the sample
      note: 1.drug#0b.t identifies no observations in the sample
      note: 1.drug#2.t omitted because of collinearity
      note: 2.drug#0b.t identifies no observations in the sample
      note: 2.drug#2.t omitted because of collinearity
      note: 3.drug#0b.t identifies no observations in the sample
      note: 3.drug#1.t omitted because of collinearity
      note: 3.drug#2.t omitted because of collinearity
      
      Fixed-effects (within) regression               Number of obs     =        282
      Group variable: id                              Number of groups  =         94
      
      R-sq:                                           Obs per group:
      within  = 0.0298                                         min =          3
      between = 0.0055                                         avg =        3.0
      overall = 0.0099                                         max =          3
      
      F(6,182)          =       0.93
      corr(u_i, Xb)  = -0.0267                        Prob > F          =     0.4745
      
      
      outcome       Coef.   Std. Err.      t    P>t     [95% Conf. Interval]
      
      drug
      1    -.0295152   .0388525    -0.76   0.448    -.1061745    .0471442
      2     .0425882   .0382769     1.11   0.267    -.0329353    .1181118
      3    -.0746296   .0429531    -1.74   0.084    -.1593797    .0101204
      
      t
      1     .0266296   .0429531     0.62   0.536    -.0581204    .1113797
      2            0  (omitted)
      
      drug#t
      0 1            0  (empty)
      0 2            0  (empty)
      1 0            0  (empty)
      1 1     .0024916   .0579179     0.04   0.966    -.1117854    .1167686
      1 2            0  (omitted)
      2 0            0  (empty)
      2 1    -.0248943   .0575334    -0.43   0.666    -.1384126    .0886239
      2 2            0  (omitted)
      3 0            0  (empty)
      3 1            0  (omitted)
      3 2            0  (omitted)
      
      _cons    .5428404   .0162779    33.35   0.000     .5107228     .574958
      
      sigma_u    .2619485
      sigma_e   .15781976
      rho   .73368277   (fraction of variance due to u_i)
      
      F test that all u_i=0: F(93, 182) = 8.26                     Prob > F = 0.0000
      
      margins drug, dydx(t)
      
      Conditional marginal effects                    Number of obs     =        282
      Model VCE    : Conventional
      
      Expression   : Linear prediction, predict()
      dy/dx w.r.t. : 1.t 2.t
      
      
      Delta-method
      dy/dx   Std. Err.      z    P>z     [95% Conf. Interval]
      
      1.t          
      drug
      0            .  (not estimable)
      1            .  (not estimable)
      2            .  (not estimable)
      3            .  (not estimable)
      
      2.t          
      drug
      0            .  (not estimable)
      1            .  (not estimable)
      2            .  (not estimable)
      3            .  (not estimable)
      
      Note: dy/dx for factor levels is the discrete change from the base level.
      
      margins drug, dydx(t) pwcompare
      
      Pairwise comparisons of conditional marginal effects
      Model VCE    : Conventional
      
      Expression   : Linear prediction, predict()
      dy/dx w.r.t. : 1.t 2.t
      
      
      Contrast Delta-method         Unadjusted
      dy/dx   Std. Err.     [95% Conf. Interval]
      
      1.t          
      drug
      1 vs 0            .  (not estimable)
      2 vs 0            .  (not estimable)
      3 vs 0            .  (not estimable)
      2 vs 1            .  (not estimable)
      3 vs 1            .  (not estimable)
      3 vs 2            .  (not estimable)
      
      2.t          
      drug
      1 vs 0            .  (not estimable)
      2 vs 0            .  (not estimable)
      3 vs 0            .  (not estimable)
      2 vs 1            .  (not estimable)
      3 vs 1            .  (not estimable)
      3 vs 2            .  (not estimable)
      
      Note: dy/dx for factor levels is the discrete change from the
      base level.
      So, also in this case the time 2 dummy is dropped.

      What do you reckon?
      ------
      I use Stata 17

      Comment


      • #4
        You have introduced problems, and additional colinearities, into your data by the way you have represented the baseline. The drug variables, in this kind of analysis, should not reflect what is actually being taken at this time, they should represent the drug to which the participant was assigned. So assigning 0 to drug, drug1, drug2, and drug3 for the baseline periods is the mistake here.

        So, in the code below, I fix the drug variable, and then run the DID estimation

        Code:
        * Example generated by -dataex-. To install: ssc install dataex
        clear
        input float(id t) double outcome float(nodrug drug1 drug2 drug3 drug) byte(t_1 t_2 t_3) float(trend trend2)
         1 0  .716 1 0 0 0 0 1 0 0 1 1
         1 1  .653 0 1 0 0 1 0 1 0 2 4
         1 2  .668 0 1 0 0 1 0 0 1 3 9
         2 0  .624 1 0 0 0 0 1 0 0 1 1
         2 1  .671 0 1 0 0 1 0 1 0 2 4
         2 2  .669 0 1 0 0 1 0 0 1 3 9
         3 0  .426 1 0 0 0 0 1 0 0 1 1
         3 1  .651 0 1 0 0 1 0 1 0 2 4
         3 2  .304 0 1 0 0 1 0 0 1 3 9
         4 0  .406 1 0 0 0 0 1 0 0 1 1
         4 1  .419 0 1 0 0 1 0 1 0 2 4
         4 2  .596 0 1 0 0 1 0 0 1 3 9
         5 0  .555 1 0 0 0 0 1 0 0 1 1
         5 1  .703 0 1 0 0 1 0 1 0 2 4
         5 2  .755 0 1 0 0 1 0 0 1 3 9
         6 0  .679 1 0 0 0 0 1 0 0 1 1
         6 1  .795 0 1 0 0 1 0 1 0 2 4
         6 2  .689 0 1 0 0 1 0 0 1 3 9
         7 0  .309 1 0 0 0 0 1 0 0 1 1
         7 1 -.112 0 1 0 0 1 0 1 0 2 4
         7 2  .169 0 1 0 0 1 0 0 1 3 9
         8 0  .813 1 0 0 0 0 1 0 0 1 1
         8 1  .661 0 1 0 0 1 0 1 0 2 4
         8 2  .716 0 1 0 0 1 0 0 1 3 9
         9 0  .635 1 0 0 0 0 1 0 0 1 1
         9 1  .422 0 1 0 0 1 0 1 0 2 4
         9 2  .292 0 1 0 0 1 0 0 1 3 9
        10 0  .541 1 0 0 0 0 1 0 0 1 1
        10 1  .533 0 1 0 0 1 0 1 0 2 4
        10 2  .555 0 1 0 0 1 0 0 1 3 9
        11 0  .063 1 0 0 0 0 1 0 0 1 1
        11 1  .107 0 1 0 0 1 0 1 0 2 4
        11 2  .045 0 1 0 0 1 0 0 1 3 9
        12 0  .321 1 0 0 0 0 1 0 0 1 1
        12 1  .336 0 1 0 0 1 0 1 0 2 4
        12 2  .294 0 1 0 0 1 0 0 1 3 9
        13 0  .303 1 0 0 0 0 1 0 0 1 1
        13 1  .293 0 1 0 0 1 0 1 0 2 4
        13 2 -.069 0 1 0 0 1 0 0 1 3 9
        14 0  .511 1 0 0 0 0 1 0 0 1 1
        14 1  .504 0 1 0 0 1 0 1 0 2 4
        14 2   .77 0 1 0 0 1 0 0 1 3 9
        15 0  .657 1 0 0 0 0 1 0 0 1 1
        15 1  .632 0 1 0 0 1 0 1 0 2 4
        15 2  .883 0 1 0 0 1 0 0 1 3 9
        16 0   .62 1 0 0 0 0 1 0 0 1 1
        16 1  .767 0 1 0 0 1 0 1 0 2 4
        16 2  .099 0 1 0 0 1 0 0 1 3 9
        17 0  .335 1 0 0 0 0 1 0 0 1 1
        17 1   .85 0 1 0 0 1 0 1 0 2 4
        17 2  .689 0 1 0 0 1 0 0 1 3 9
        18 0  .426 1 0 0 0 0 1 0 0 1 1
        18 1  .668 0 1 0 0 1 0 1 0 2 4
        18 2  .283 0 1 0 0 1 0 0 1 3 9
        19 0  .517 1 0 0 0 0 1 0 0 1 1
        19 1  .171 0 1 0 0 1 0 1 0 2 4
        19 2  .603 0 1 0 0 1 0 0 1 3 9
        20 0  .709 1 0 0 0 0 1 0 0 1 1
        20 1  .531 0 1 0 0 1 0 1 0 2 4
        20 2  .345 0 1 0 0 1 0 0 1 3 9
        21 0  .548 1 0 0 0 0 1 0 0 1 1
        21 1   .71 0 1 0 0 1 0 1 0 2 4
        21 2  .206 0 1 0 0 1 0 0 1 3 9
        22 0  .635 1 0 0 0 0 1 0 0 1 1
        22 1  .583 0 1 0 0 1 0 1 0 2 4
        22 2  .627 0 1 0 0 1 0 0 1 3 9
        23 0  .703 1 0 0 0 0 1 0 0 1 1
        23 1  .735 0 1 0 0 1 0 1 0 2 4
        23 2  .723 0 1 0 0 1 0 0 1 3 9
        24 0  .479 1 0 0 0 0 1 0 0 1 1
        24 1  .496 0 1 0 0 1 0 1 0 2 4
        24 2   .62 0 1 0 0 1 0 0 1 3 9
        25 0 -.208 1 0 0 0 0 1 0 0 1 1
        25 1 -.353 0 1 0 0 1 0 1 0 2 4
        25 2  .602 0 1 0 0 1 0 0 1 3 9
        26 0  .598 1 0 0 0 0 1 0 0 1 1
        26 1  .635 0 1 0 0 1 0 1 0 2 4
        26 2  .494 0 1 0 0 1 0 0 1 3 9
        27 0  .836 1 0 0 0 0 1 0 0 1 1
        27 1  .826 0 1 0 0 1 0 1 0 2 4
        27 2  .392 0 1 0 0 1 0 0 1 3 9
        28 0   .32 1 0 0 0 0 1 0 0 1 1
        28 1  .099 0 1 0 0 1 0 1 0 2 4
        28 2  .081 0 1 0 0 1 0 0 1 3 9
        29 0  .575 1 0 0 0 0 1 0 0 1 1
        29 1  .487 0 1 0 0 1 0 1 0 2 4
        29 2  .836 0 1 0 0 1 0 0 1 3 9
        30 0  .906 1 0 0 0 0 1 0 0 1 1
        30 1  .906 0 1 0 0 1 0 1 0 2 4
        30 2  .826 0 1 0 0 1 0 0 1 3 9
        31 0  .689 1 0 0 0 0 1 0 0 1 1
        31 1  .735 0 1 0 0 1 0 1 0 2 4
        31 2  .491 0 1 0 0 1 0 0 1 3 9
        32 0  .826 1 0 0 0 0 1 0 0 1 1
        32 1  .877 0 1 0 0 1 0 1 0 2 4
        32 2  .777 0 1 0 0 1 0 0 1 3 9
        33 0  .768 1 0 0 0 0 1 0 0 1 1
        33 1  .837 0 1 0 0 1 0 1 0 2 4
        33 2  .837 0 1 0 0 1 0 0 1 3 9
        34 0  .645 1 0 0 0 0 1 0 0 1 1
        34 1  .627 0 0 1 0 2 0 1 0 2 4
        34 2  .632 0 0 1 0 2 0 0 1 3 9
        35 0  .883 1 0 0 0 0 1 0 0 1 1
        35 1  .836 0 0 1 0 2 0 1 0 2 4
        35 2  .814 0 0 1 0 2 0 0 1 3 9
        36 0  .716 1 0 0 0 0 1 0 0 1 1
        36 1  .691 0 0 1 0 2 0 1 0 2 4
        36 2  .393 0 0 1 0 2 0 0 1 3 9
        37 0  .451 1 0 0 0 0 1 0 0 1 1
        37 1   .42 0 0 1 0 2 0 1 0 2 4
        37 2  .706 0 0 1 0 2 0 0 1 3 9
        38 0   .61 1 0 0 0 0 1 0 0 1 1
        38 1  .555 0 0 1 0 2 0 1 0 2 4
        38 2   .56 0 0 1 0 2 0 0 1 3 9
        39 0   .08 1 0 0 0 0 1 0 0 1 1
        39 1  .491 0 0 1 0 2 0 1 0 2 4
        39 2  .515 0 0 1 0 2 0 0 1 3 9
        40 0  .494 1 0 0 0 0 1 0 0 1 1
        40 1   .62 0 0 1 0 2 0 1 0 2 4
        40 2  .466 0 0 1 0 2 0 0 1 3 9
        41 0  .516 1 0 0 0 0 1 0 0 1 1
        41 1  .516 0 0 1 0 2 0 1 0 2 4
        41 2  .378 0 0 1 0 2 0 0 1 3 9
        42 0 -.014 1 0 0 0 0 1 0 0 1 1
        42 1 -.107 0 0 1 0 2 0 1 0 2 4
        42 2  .132 0 0 1 0 2 0 0 1 3 9
        43 0  .605 1 0 0 0 0 1 0 0 1 1
        43 1  .635 0 0 1 0 2 0 1 0 2 4
        43 2  .622 0 0 1 0 2 0 0 1 3 9
        44 0  .226 1 0 0 0 0 1 0 0 1 1
        44 1  .567 0 0 1 0 2 0 1 0 2 4
        44 2  .066 0 0 1 0 2 0 0 1 3 9
        45 0  .057 1 0 0 0 0 1 0 0 1 1
        45 1   .26 0 0 1 0 2 0 1 0 2 4
        45 2  .691 0 0 1 0 2 0 0 1 3 9
        46 0  .433 1 0 0 0 0 1 0 0 1 1
        46 1   .32 0 0 1 0 2 0 1 0 2 4
        46 2  .716 0 0 1 0 2 0 0 1 3 9
        47 0  .645 1 0 0 0 0 1 0 0 1 1
        47 1  .848 0 0 1 0 2 0 1 0 2 4
        47 2  .812 0 0 1 0 2 0 0 1 3 9
        48 0  .883 1 0 0 0 0 1 0 0 1 1
        48 1  .812 0 0 1 0 2 0 1 0 2 4
        48 2  .812 0 0 1 0 2 0 0 1 3 9
        49 0  .432 1 0 0 0 0 1 0 0 1 1
        49 1  .758 0 0 1 0 2 0 1 0 2 4
        49 2  .758 0 0 1 0 2 0 0 1 3 9
        50 0  .206 1 0 0 0 0 1 0 0 1 1
        50 1  .201 0 0 1 0 2 0 1 0 2 4
        50 2 -.134 0 0 1 0 2 0 0 1 3 9
        51 0  .698 1 0 0 0 0 1 0 0 1 1
        51 1   .62 0 0 1 0 2 0 1 0 2 4
        51 2  .427 0 0 1 0 2 0 0 1 3 9
        52 0   .58 1 0 0 0 0 1 0 0 1 1
        52 1  .836 0 0 1 0 2 0 1 0 2 4
        52 2  .723 0 0 1 0 2 0 0 1 3 9
        53 0 -.042 1 0 0 0 0 1 0 0 1 1
        53 1 -.041 0 0 1 0 2 0 1 0 2 4
        53 2  .304 0 0 1 0 2 0 0 1 3 9
        54 0  .814 1 0 0 0 0 1 0 0 1 1
        54 1  .743 0 0 1 0 2 0 1 0 2 4
        54 2  .762 0 0 1 0 2 0 0 1 3 9
        55 0  .767 1 0 0 0 0 1 0 0 1 1
        55 1   .74 0 0 1 0 2 0 1 0 2 4
        55 2  .767 0 0 1 0 2 0 0 1 3 9
        56 0  .689 1 0 0 0 0 1 0 0 1 1
        56 1  .836 0 0 1 0 2 0 1 0 2 4
        56 2  .906 0 0 1 0 2 0 0 1 3 9
        57 0  .604 1 0 0 0 0 1 0 0 1 1
        57 1  .678 0 0 1 0 2 0 1 0 2 4
        57 2  .654 0 0 1 0 2 0 0 1 3 9
        58 0  .639 1 0 0 0 0 1 0 0 1 1
        58 1  .806 0 0 1 0 2 0 1 0 2 4
        58 2    .6 0 0 1 0 2 0 0 1 3 9
        59 0  .627 1 0 0 0 0 1 0 0 1 1
        59 1  .531 0 0 1 0 2 0 1 0 2 4
        59 2   .71 0 0 1 0 2 0 0 1 3 9
        60 0  .635 1 0 0 0 0 1 0 0 1 1
        60 1  .321 0 0 1 0 2 0 1 0 2 4
        60 2  .335 0 0 1 0 2 0 0 1 3 9
        61 0  .185 1 0 0 0 0 1 0 0 1 1
        61 1  .678 0 0 1 0 2 0 1 0 2 4
        61 2  .686 0 0 1 0 2 0 0 1 3 9
        62 0  .727 1 0 0 0 0 1 0 0 1 1
        62 1  .555 0 0 1 0 2 0 1 0 2 4
        62 2  .511 0 0 1 0 2 0 0 1 3 9
        63 0  .587 1 0 0 0 0 1 0 0 1 1
        63 1  .648 0 0 1 0 2 0 1 0 2 4
        63 2  .698 0 0 1 0 2 0 0 1 3 9
        64 0  .778 1 0 0 0 0 1 0 0 1 1
        64 1  .836 0 0 1 0 2 0 1 0 2 4
        64 2  .778 0 0 1 0 2 0 0 1 3 9
        65 0  .393 1 0 0 0 0 1 0 0 1 1
        65 1  .246 0 0 1 0 2 0 1 0 2 4
        65 2  .221 0 0 1 0 2 0 0 1 3 9
        66 0  .906 1 0 0 0 0 1 0 0 1 1
        66 1  .765 0 0 1 0 2 0 1 0 2 4
        66 2  .837 0 0 1 0 2 0 0 1 3 9
        67 0  .698 1 0 0 0 0 1 0 0 1 1
        67 1  .812 0 0 1 0 2 0 1 0 2 4
        67 2  .743 0 0 1 0 2 0 0 1 3 9
        68 0 -.427 1 0 0 0 0 1 0 0 1 1
        68 1  -.51 0 0 0 1 3 0 1 0 2 4
        68 2 -.594 0 0 0 1 3 0 0 1 3 9
        69 0  .558 1 0 0 0 0 1 0 0 1 1
        69 1  .546 0 0 0 1 3 0 1 0 2 4
        69 2  .344 0 0 0 1 3 0 0 1 3 9
        70 0  .622 1 0 0 0 0 1 0 0 1 1
        70 1  .743 0 0 0 1 3 0 1 0 2 4
        70 2  .607 0 0 0 1 3 0 0 1 3 9
        71 0  .045 1 0 0 0 0 1 0 0 1 1
        71 1  .291 0 0 0 1 3 0 1 0 2 4
        71 2  .338 0 0 0 1 3 0 0 1 3 9
        72 0  .906 1 0 0 0 0 1 0 0 1 1
        72 1  .906 0 0 0 1 3 0 1 0 2 4
        72 2  .735 0 0 0 1 3 0 0 1 3 9
        73 0  .617 1 0 0 0 0 1 0 0 1 1
        73 1   .76 0 0 0 1 3 0 1 0 2 4
        73 2  .393 0 0 0 1 3 0 0 1 3 9
        74 0  .806 1 0 0 0 0 1 0 0 1 1
        74 1  .836 0 0 0 1 3 0 1 0 2 4
        74 2  .906 0 0 0 1 3 0 0 1 3 9
        75 0   .55 1 0 0 0 0 1 0 0 1 1
        75 1  .763 0 0 0 1 3 0 1 0 2 4
        75 2   .74 0 0 0 1 3 0 0 1 3 9
        76 0     1 1 0 0 0 0 1 0 0 1 1
        76 1     1 0 0 0 1 3 0 1 0 2 4
        76 2  .837 0 0 0 1 3 0 0 1 3 9
        77 0  .836 1 0 0 0 0 1 0 0 1 1
        77 1  .636 0 0 0 1 3 0 1 0 2 4
        77 2  .836 0 0 0 1 3 0 0 1 3 9
        78 0  .617 1 0 0 0 0 1 0 0 1 1
        78 1  .725 0 0 0 1 3 0 1 0 2 4
        78 2  .722 0 0 0 1 3 0 0 1 3 9
        79 0  .689 1 0 0 0 0 1 0 0 1 1
        79 1  .671 0 0 0 1 3 0 1 0 2 4
        79 2  .837 0 0 0 1 3 0 0 1 3 9
        80 0  .378 1 0 0 0 0 1 0 0 1 1
        80 1  .378 0 0 0 1 3 0 1 0 2 4
        80 2  .019 0 0 0 1 3 0 0 1 3 9
        81 0   .71 1 0 0 0 0 1 0 0 1 1
        81 1  .728 0 0 0 1 3 0 1 0 2 4
        81 2  .739 0 0 0 1 3 0 0 1 3 9
        82 0  .584 1 0 0 0 0 1 0 0 1 1
        82 1  .504 0 0 0 1 3 0 1 0 2 4
        82 2  .752 0 0 0 1 3 0 0 1 3 9
        83 0   .71 1 0 0 0 0 1 0 0 1 1
        83 1   .71 0 0 0 1 3 0 1 0 2 4
        83 2  .721 0 0 0 1 3 0 0 1 3 9
        84 0  .727 1 0 0 0 0 1 0 0 1 1
        84 1  .821 0 0 0 1 3 0 1 0 2 4
        84 2  .691 0 0 0 1 3 0 0 1 3 9
        85 0  .659 1 0 0 0 0 1 0 0 1 1
        85 1  .821 0 0 0 1 3 0 1 0 2 4
        85 2   .72 0 0 0 1 3 0 0 1 3 9
        86 0  .758 1 0 0 0 0 1 0 0 1 1
        86 1   .74 0 0 0 1 3 0 1 0 2 4
        86 2  .671 0 0 0 1 3 0 0 1 3 9
        87 0  .836 1 0 0 0 0 1 0 0 1 1
        87 1  .716 0 0 0 1 3 0 1 0 2 4
        87 2  .422 0 0 0 1 3 0 0 1 3 9
        88 0  .554 1 0 0 0 0 1 0 0 1 1
        88 1 -.112 0 0 0 1 3 0 1 0 2 4
        88 2  .363 0 0 0 1 3 0 0 1 3 9
        89 0  .836 1 0 0 0 0 1 0 0 1 1
        89 1  .728 0 0 0 1 3 0 1 0 2 4
        89 2  .691 0 0 0 1 3 0 0 1 3 9
        90 0 -.134 1 0 0 0 0 1 0 0 1 1
        90 1 -.268 0 0 0 1 3 0 1 0 2 4
        90 2 -.429 0 0 0 1 3 0 0 1 3 9
        91 0  .213 1 0 0 0 0 1 0 0 1 1
        91 1  .011 0 0 0 1 3 0 1 0 2 4
        91 2  .255 0 0 0 1 3 0 0 1 3 9
        92 0  .521 1 0 0 0 0 1 0 0 1 1
        92 1  .398 0 0 0 1 3 0 1 0 2 4
        92 2  .325 0 0 0 1 3 0 0 1 3 9
        93 0  .479 1 0 0 0 0 1 0 0 1 1
        93 1 -.218 0 0 0 1 3 0 1 0 2 4
        93 2   -.2 0 0 0 1 3 0 0 1 3 9
        94 0  .383 1 0 0 0 0 1 0 0 1 1
        94 1  .413 0 0 0 1 3 0 1 0 2 4
        94 2  .577 0 0 0 1 3 0 0 1 3 9
        end
        
        //    REPAIR THE DRUG VARIABLE
        by id (t), sort: assert drug == drug[_N] if drug != 0
        by id (t): replace drug = drug[_N]
        
        //    DO THE DID ESTIMATION
        xtset id t
        xtreg outcome i.drug##i.t, fe
        margins drug#t, noestimcheck
        marginsplot, xdimension(t)
        margins drug, dydx(t) pwcompare(effects) noestimcheck
        Note also that with just 3 time periods, it does not make sense to fit a quadratic model of time trend; it becomes just a strange algebraic transform of the model with discrete time and achieves no real parsimony. If you want to fit a linear trend model, go ahead:

        Code:
        xtreg outcome i.drug##c.t, fe
        All of the strange behavior with regard to colinearity you observed earlier was due to this misrepresentation of the drug variable.

        Comment


        • #5
          Thank you very much Clyde, really spot on!
          ------
          I use Stata 17

          Comment

          Working...
          X