Announcement

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

  • Difference in Difference Analysis in Stata 16

    Hi, I am trying to run a difference in difference analysis, and have graph output in Stata 16. I know Stata 17 makes this easy, but I have the earlier version and have not been able to figure out how to do this. I am trying to evaluate the effect of Medicaid expansion on use of a treatment in 2 separate time periods (2010-2012) and (2014-2016).
    I created dummy variables for Medicaid expansion (ME_dummy) and the times (time_period), and then ran this code to look for use of the treatment (Drug) with some other covariates.
    diff Drug, treated( ME_dummy ) period( time_period ) cov ( Race FacilityType Location)

    Is this correct? Drug administration is a Y/N. Also, how do I make a graph for this?
    Thanks for your help!

  • #2
    Hey Ann. Welcome to Statalist. Please show me your data using the dataex command.

    Comment


    • #3
      Thanks Jared. I have attached the dataset in an excel file. Appreciate your help!
      Attached Files

      Comment


      • #4
        I'm not on my computer right now, and it would help others for you to use dataex since it allows us to have the exact same dataset you have without needing to import your file.

        Some folks, at their jobs/universities, aren't allowed to risk the safety of their computers by downloading unknown files, so dataex is the best way to show your dataset to others.

        So, please present your data using dataex so I may see what you're seeing.

        Comment


        • #5
          I tried to but don't seem to be able to create the whole dataset that way. The dataset has 2300 rows, and this only allows 100? I haven't used dataex before so may not be doing it the right way

          Comment


          • #6
            This is what I have. Not sure if it is right:

            Code:
            * Example generated by -dataex-. To install: ssc install dataex
            clear
            input byte(age Gender InsuranceStatus Location Race Age RuralUrban OneYrSurvival ThreeYrSurvival FiveYrSurvival Stage_AJCC8excludingStage4 Drug Mexpansion MetroUrbanRural) double time_period byte(ME_dummy DinD Palliation _diff)
            83 0 2 2 0 2 1 0 0 0 . 0 0 0 1 0 . 0 .
            78 0 2 3 0 1 1 1 0 0 0 0 0 0 1 0 . 0 .
            71 0 2 3 0 1 1 0 0 0 . 0 0 0 1 0 . 0 .
            83 1 2 2 0 2 1 0 0 0 . 0 0 0 1 0 . 0 .
            54 1 0 2 0 0 1 1 0 0 0 0 0 0 1 0 . 0 .
            56 1 0 1 5 0 1 0 0 0 . 1 0 0 1 0 . 1 .
            72 1 2 1 0 1 1 0 0 0 . 0 0 1 1 0 . 0 .
            65 1 2 3 0 1 1 1 0 0 2 1 0 0 1 0 . 1 .
            74 0 2 3 1 1 1 0 0 0 . 0 0 0 1 1 . 0 .
            82 0 2 3 0 2 1 1 0 0 . 1 0 0 1 0 . 1 .
            85 1 2 3 0 2 1 0 0 0 . 0 0 0 1 0 . 0 .
            82 1 3 1 0 2 1 1 0 0 . 0 0 1 1 1 . 0 .
            60 1 0 3 0 1 1 1 1 1 0 0 0 0 1 1 . 0 .
            77 0 2 3 0 1 1 0 0 0 . 0 0 1 1 0 . 0 .
            75 1 2 3 1 1 1 0 0 0 . 0 0 0 1 0 . 0 .
            80 0 0 2 1 2 1 0 0 0 . 0 0 0 1 1 . 0 .
            83 0 2 2 0 2 1 0 0 0 . 0 0 0 0 1 . 0 .
            75 1 2 1 0 1 1 1 0 0 0 0 0 0 0 0 . 0 .
            74 1 0 1 5 1 1 0 0 0 . 0 0 0 0 0 . 0 .
            75 1 2 2 0 1 1 0 0 0 . 1 0 0 0 0 . 1 .
            80 1 2 0 2 2 1 0 0 0 . 0 0 0 0 0 . 0 .
            77 1 2 3 0 1 1 0 0 0 . 0 0 0 0 0 . 0 .
            86 1 2 3 0 2 1 0 0 0 2 0 0 0 0 0 . 0 .
            64 0 0 3 0 1 0 1 0 0 1 0 0 2 0 1 . 0 .
            75 0 2 0 0 1 1 1 1 0 2 0 0 0 0 1 . 0 .
            35 1 0 . 0 . 1 1 1 1 1 0 0 0 1 1 . 0 .
            77 1 2 2 0 1 1 0 0 0 . 0 0 0 0 1 . 0 .
            56 0 4 3 0 0 1 0 0 0 . 0 0 0 0 1 . 0 .
            67 0 2 3 0 1 1 0 0 0 . 0 0 0 0 1 . 0 .
            67 1 2 2 0 1 1 0 0 0 . 0 0 0 0 0 . 0 .
            57 0 0 1 0 0 1 1 0 0 . 0 0 0 0 0 . 0 .
            63 1 0 0 0 1 1 0 0 0 2 0 0 1 1 0 . 0 .
            73 1 2 1 0 1 1 0 0 0 . 0 0 0 0 0 . 0 .
            73 0 0 1 0 1 1 0 0 0 . 0 0 0 0 0 . 0 .
            87 1 2 1 0 2 1 0 0 0 . 0 0 0 0 0 . 0 .
            68 0 2 2 0 1 1 1 0 0 2 0 0 0 0 0 . 0 .
            52 1 1 1 0 0 1 0 0 0 . 0 0 0 0 0 . 0 .
            53 0 2 3 0 0 1 0 0 0 . 0 0 1 0 0 . 0 .
            84 0 2 1 0 2 1 0 0 0 . 0 0 0 0 0 . 0 .
            73 1 2 1 0 1 1 0 0 0 0 0 0 0 0 0 . 0 .
            71 1 2 3 0 1 1 1 1 0 0 0 0 0 0 0 . 0 .
            58 1 2 3 1 0 1 0 0 0 . 0 0 0 1 0 . 0 .
            84 1 2 1 0 2 1 1 0 0 . 1 0 0 0 0 . 1 .
            77 1 2 1 1 1 1 0 0 0 . 0 0 0 0 0 . 0 .
            87 0 2 2 0 2 1 0 0 0 . 0 0 0 0 0 . 0 .
            48 1 3 1 0 0 1 0 0 0 . 0 0 0 0 0 . 0 .
            84 0 2 2 0 2 1 0 0 0 . 0 0 0 0 1 . 0 .
            73 0 2 3 1 1 1 0 0 0 2 0 0 0 1 1 . 0 .
            44 0 1 3 0 0 1 0 0 0 . 0 0 0 0 1 . 0 .
            83 0 2 1 0 2 1 0 0 0 . 0 0 0 0 1 . 0 .
            54 0 0 3 1 0 1 0 0 0 . 0 0 0 0 0 . 0 .
            51 1 0 0 0 0 1 1 0 0 2 0 0 0 0 0 . 0 .
            60 1 0 1 0 1 1 0 0 0 . 0 0 1 0 0 . 0 .
            69 1 2 1 0 1 1 0 0 0 . 0 0 0 0 0 . 0 .
            69 0 2 1 0 1 1 0 0 0 . 0 0 0 0 1 . 0 .
            59 0 0 2 0 0 1 1 0 0 2 0 0 0 0 0 . 0 .
            75 0 2 1 0 1 1 0 0 0 . 0 0 0 0 0 . 0 .
            72 0 2 3 0 1 1 0 0 0 1 0 0 0 1 1 . 0 .
            63 0 2 3 0 1 1 0 0 0 . 0 0 1 0 1 . 0 .
            89 0 2 2 0 2 1 0 0 0 . 1 0 0 0 0 . 1 .
            75 1 2 2 0 1 1 0 0 0 . 0 0 0 0 0 . 0 .
            70 1 2 1 0 1 1 0 0 0 1 0 0 0 0 1 . 0 .
            77 0 2 3 0 1 1 1 1 1 0 0 0 0 0 1 . 0 .
            61 0 0 2 0 1 1 0 0 0 . 0 0 0 1 0 . 0 .
            65 0 2 2 0 1 1 0 0 0 . 0 0 0 1 0 . 0 .
            64 0 2 1 0 1 1 1 1 0 1 0 0 0 1 0 . 0 .
            70 1 2 1 0 1 1 0 0 0 . 0 0 0 1 0 . 0 .
            86 1 2 1 0 2 1 0 0 0 . 0 0 0 1 0 . 0 .
            62 0 0 2 0 1 1 1 0 0 . 0 0 0 1 0 . 0 .
            77 0 2 3 0 1 1 1 0 0 . 0 0 1 1 1 . 0 .
            60 0 0 1 0 1 1 1 1 1 . 0 0 0 1 1 . 0 .
            71 0 2 3 0 1 1 1 1 1 . 0 0 0 1 1 . 0 .
            89 1 2 1 0 2 1 0 0 0 . 0 0 0 1 1 . 0 .
            52 0 0 1 1 0 1 1 1 1 1 0 0 0 1 1 . 0 .
            53 1 0 3 1 0 1 0 0 0 . 1 0 0 1 1 . 1 .
            69 1 2 3 0 1 1 1 1 1 . 0 0 0 0 0 . 0 .
            60 0 0 2 0 1 1 0 0 0 . 0 0 1 0 0 . 0 .
            61 1 1 2 0 1 1 0 0 0 2 0 0 1 0 0 . 0 .
            66 0 2 1 0 1 1 1 1 1 0 0 0 0 0 0 . 0 .
            56 0 0 2 0 0 1 0 0 0 . 0 0 0 0 0 . 0 .
            66 0 2 3 0 1 1 0 0 0 . 0 0 0 0 0 . 0 .
            65 0 0 1 0 1 1 0 0 0 1 0 0 0 0 0 . 0 .
            86 0 2 1 0 2 1 0 0 0 2 0 0 0 0 0 . 0 .
            42 1 1 0 2 0 1 0 0 0 . 0 0 0 0 0 . 0 .
            88 1 2 3 1 2 1 0 0 0 . 0 0 0 1 0 . 0 .
            90 0 2 1 0 2 1 0 0 0 . 1 0 0 0 0 . 1 .
            73 1 2 0 0 1 1 0 0 0 . 0 0 1 0 0 . 0 .
            85 1 2 3 0 2 1 0 0 0 . 0 0 0 0 0 . 0 .
            51 1 2 3 0 0 1 0 0 0 . 0 0 1 0 0 . 0 .
            73 0 2 3 0 1 1 0 0 0 . 0 0 0 0 0 . 0 .
            86 1 2 1 0 2 1 0 0 0 . 0 0 0 1 0 . 0 .
            81 1 2 1 0 2 1 0 0 0 . 0 0 0 0 0 . 0 .
            50 0 0 3 0 0 1 0 0 0 2 1 0 0 0 0 . 1 .
            74 0 2 3 0 1 1 0 0 0 . 0 0 0 0 0 . 0 .
            81 0 2 3 0 2 1 0 0 0 . 0 0 0 0 0 . 0 .
            77 0 2 1 0 1 1 0 0 0 . 1 0 0 0 0 . 1 .
            90 0 2 1 0 2 1 0 0 0 . 0 0 0 0 0 . 0 .
            76 0 2 0 0 1 1 1 0 0 . 0 0 0 0 0 . 0 .
            62 0 3 3 0 1 1 0 0 0 . 0 0 0 0 0 . 0 .
            80 0 2 3 0 2 1 1 0 0 . 0 0 0 0 0 . 0 .
            end

            Comment


            • #7
              Okay and just so I understand, your question is about whether or not your code is correct, yes?


              It seems all you'd need is

              Code:
              reg Drug, i.ME_dummy##c.time_period Race FacilityType Location
              your data structure seems simple, so you won't need anything too complicated.

              Comment


              • #8
                Thank you. This is the output.

                Source | SS df MS Number of obs = 2,268
                -------------+---------------------------------- F(5, 2262) = 1.45
                Model | .840209746 5 .168041949 Prob > F = 0.2034
                Residual | 262.263847 2,262 .115943345 R-squared = 0.0032
                -------------+---------------------------------- Adj R-squared = 0.0010
                Total | 263.104056 2,267 .116058252 Root MSE = .3405

                ----------------------------------------------------------------------------------------
                Drug | Coef. Std. Err. t P>|t| [95% Conf. Interval]
                -----------------------+----------------------------------------------------------------
                1.ME_dummy | -.0587355 .0483242 -1.22 0.224 -.1534998 .0360289
                time_period | .0109822 .0232657 0.47 0.637 -.0346422 .0566066
                |
                ME_dummy#c.time_period |
                1 | -.0311913 .086341 -0.36 0.718 -.2005071 .1381245
                |
                Race | -.0015586 .0093362 -0.17 0.867 -.019867 .0167498
                Location | .0140773 .0069246 2.03 0.042 .0004981 .0276566
                _cons | .0894536 .0148474 6.02 0.000 .0603376 .1185697
                ----------------------------------------------------------------------------------------

                To clarify, does the ME_dummy#c.time_period indicate the DinD? So negative change, but not significant. I know how to do this manually, but I don't understand this syntax. appreciate the help!

                Comment


                • #9
                  I'm used to seeing output for control and treated similar to this output below but I don't see those numbers here.

                  DIFFERENCE-IN-DIFFERENCES ESTIMATION RESULTS
                  Number of observations in the DIFF-IN-DIFF: 2268
                  Before After
                  Control: 1493 182 1675
                  Treated: 40 26 66
                  1533 208
                  --------------------------------------------------------
                  Outcome var. | Drug | S. Err. | |t| | P>|t|
                  ----------------+---------+---------+---------+---------
                  Before | | | |
                  Control | 0.089 | | |
                  Treated | 0.031 | | |
                  Diff (T-C) | -0.059 | 0.048 | -1.22 | 0.224
                  After | | | |
                  Control | 0.100 | | |
                  Treated | 0.011 | | |
                  Diff (T-C) | -0.090 | 0.071 | 1.27 | 0.204
                  | | | |
                  Diff-in-Diff | -0.031 | 0.086 | 0.36 | 0.718
                  --------------------------------------------------------
                  R-square: 0.00
                  * Means and Standard Errors are estimated by linear regression
                  **Inference: *** p<0.01; ** p<0.05; * p<0.1

                  I'm not sure how to interpret..

                  Comment


                  • #10
                    Also could you share the code that would allow me to show this output as a graph?

                    Comment


                    • #11
                      I can, but can you present the tables in code delimiters so I can better read what's going on?

                      Comment


                      • #12
                        Code:
                             Source |       SS           df       MS      Number of obs   =     2,268
                        -------------+----------------------------------   F(5, 2262)      =      1.45
                               Model |  .840209746         5  .168041949   Prob > F        =    0.2034
                            Residual |  262.263847     2,262  .115943345   R-squared       =    0.0032
                        -------------+----------------------------------   Adj R-squared   =    0.0010
                               Total |  263.104056     2,267  .116058252   Root MSE        =     .3405
                        
                        ----------------------------------------------------------------------------------------
                                          Drug |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
                        -----------------------+----------------------------------------------------------------
                                    1.ME_dummy |  -.0587355   .0483242    -1.22   0.224    -.1534998    .0360289
                                   time_period |   .0109822   .0232657     0.47   0.637    -.0346422    .0566066
                                               |
                        ME_dummy#c.time_period |
                                            1  |  -.0311913    .086341    -0.36   0.718    -.2005071    .1381245
                                               |
                                          Race |  -.0015586   .0093362    -0.17   0.867     -.019867    .0167498
                                      Location |   .0140773   .0069246     2.03   0.042     .0004981    .0276566
                                         _cons |   .0894536   .0148474     6.02   0.000     .0603376    .1185697
                        ----------------------------------------------------------------------------------------
                        Last edited by Ann Fonseca; 08 Mar 2022, 16:49.

                        Comment


                        • #13
                          Okay much better. Now, when you say present the results graphically, what do you mean? Do you mean like actually plot the regression coefficients, or do you want to visually depict the counterfactual?

                          Oh and by the way, notice how your differences-in-differences command and my reg command produce identical results

                          Comment


                          • #14
                            I noticed that- thanks! Yes, I mean visually depict the counterfactual.

                            Comment


                            • #15
                              I'm not at my computer right now, but here is what you seek. In the do files the authors provide in this article, they show you how to, from regular regression commands, remove the effect of the coefficient within the context of time series data. You can do the same thing as far as I'm aware with your setup (even though I've never done this with DD). In the end, it looks cool because you can literally see the counterfactual. So the do files here have what you seek, and I would advise you to read the paper in general since it provides really good information on graphical presentation of causal analysis in general Ann Fonseca

                              Comment

                              Working...
                              X