Announcement

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

  • DID Model

    I want to create this DID model: 𝑦𝑖𝑑 = 𝛼 + πœŒπ‘– + πœ†π‘‘ + 𝛽𝑑𝐷𝑖 + πœ–π‘–π‘‘,
    Where 𝑦𝑖𝑑 is the Saidin Index for hospital 𝑖 in year 𝑑, πœŒπ‘– and πœ†π‘‘ are fixed effects for the hospital and year, respectively, 𝐷𝑖 is a treatment status dummy, and πœ–π‘–π‘‘ is a hospital-year specific error term. 𝛽𝑑 is the treatment effect specific to year 𝑑, and is allowed to vary over time.

    Note that the treatment is β€œon” for treated hospitals in all years of the panel.

    Output: Create a separate dataset containing your estimates for 𝛽𝑑, 95% confidence interval bounds for 𝛽𝑑, as well as the mean Saidin Index for the control group and treatment group in each year. This dataset should have one observation per year. Name the variable containing your estimates for 𝛽𝑑 in each year tr_effect, the upper CI bound tr_hi, the lower CI bound tr_lo, the control group mean cr_mean, and the treatment group mean tr_mean. Hints: 1) When you estimate this model, it will be convenient to let 2004, the year of treatment, be the base (β€œomitted”) category. Framed different, all point estimates should be normalized to zero in 2004. Think about what the coefficients estimated for the periods before and after 2004 represent to see why this is.

    Dataset looks like this
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str6 prov_id int year byte(tech_num tau teach) int beds byte(nonprof govt treat _merge) float(N_t a_kt saidin)
    "11z111" 2001 17 1 0 35 0 1 0 3 1305  .0934866 .53716475
    "11z111" 2001  2 0 0 35 0 1 0 3 1305         1 .53716475
    "11z111" 2001 28 0 0 35 0 1 0 3 1305         1 .53716475
    "11z111" 2001  7 0 0 35 0 1 0 3 1305 .27969348 .53716475
    end
    label values _merge _merge
    label def _merge 3 "Matched (3)", modify
    TIA.

  • #2
    To create the Difference-in-Differences (DID) model you described in Stata, you can use the xtreg command with fixed effects. Here’s how you can do it:
    Code:
    xtset prov_id year
    gen treat_year = treat * year
    xtreg saidin i.year##i.treat, fe vce(cluster prov_id)
    This code first sets prov_id and year as the panel variables. Then, it creates an interaction term treat_year between the treatment status dummy treat and the year. The xtreg command is used to estimate the fixed effects model with year and treatment status as the main effects and their interaction as the additional effect. The vce(cluster prov_id) option is used to adjust the standard errors for clustering at the hospital level.

    To create a separate dataset containing your estimates for 𝛽𝑑, 95% confidence interval bounds for 𝛽𝑑, as well as the mean Saidin Index for the control group and treatment group in each year, you can use the margins and marginsplot commands:
    Code:
    margins year, at(treat=(0 1)) post
    marginsplot, yline(0)
    This code first calculates the marginal effects of year at the specified values of treat (0 and 1). The post option is used to store the results as if they were estimated from a regression command, which allows you to use them in subsequent commands. The marginsplot command is then used to create a plot of the marginal effects, with a reference line at 0.

    Comment


    • #3
      code: margins year, at(treat=(0 1)) post

      output:
      Adjusted predictions Number of obs = 13,050
      Model VCE: Robust

      Expression: Linear prediction, predict()
      1._at: treat = 0
      2._at: treat = 1

      ------------------------------------------------------------------------------
      | Delta-method
      | Margin std. err. z P>|z| [95% conf. interval]
      -------------+----------------------------------------------------------------
      _at#year |
      1 2001 | . (not estimable)
      1 2002 | . (not estimable)
      1 2003 | . (not estimable)
      1 2004 | . (not estimable)
      1 2005 | . (not estimable)
      1 2006 | . (not estimable)
      1 2007 | . (not estimable)
      1 2008 | . (not estimable)
      1 2009 | . (not estimable)
      1 2010 | . (not estimable)
      2 2001 | . (not estimable)
      2 2002 | . (not estimable)
      2 2003 | . (not estimable)
      2 2004 | . (not estimable)
      2 2005 | . (not estimable)
      2 2006 | . (not estimable)
      2 2007 | . (not estimable)
      2 2008 | . (not estimable)
      2 2009 | . (not estimable)
      2 2010 | . (not estimable)
      ------------------------------------------------------------------------------

      1. All the margins are missing values.
      2. It does not make any changes to the dataset.
      3. I think this model takes the year 2001 as ref year- which is omitted. I want to keep 2004 as the base (β€œomitted”) category.

      copy pasting this here: Create a separate dataset containing your estimates for 𝛽𝑑, 95% confidence interval bounds for 𝛽𝑑, as well as the mean Saidin Index for the control group and treatment group in each year. This dataset should have one observation per year. Name the variable containing your estimates for 𝛽𝑑 in each year tr_effect, the upper CI bound tr_hi, the lower CI bound tr_lo, the control group mean cr_mean, and the treatment group mean tr_mean.

      Hints: 1) When you estimate this model, it will be convenient to let 2004, the year of treatment, be the base (β€œomitted”) category. Framed different, all point estimates should be normalized to zero in 2004. Think about what the coefficients estimated for the periods before and after 2004 represent to see why this is.

      The dataset I pasted in my first request, I have not copy pasted all the values. i have just added a sub-sample of values
      Last edited by Dimple khattar khattar; 29 Apr 2024, 13:29.

      Comment


      • #4
        I also want to visualise estimates in treatment and control group means, and show the change in both groups, both before and after the year preceding treatment (i.e. 2004). I also want to add 95% confidence interval bounds for the treatment effect.

        Comment

        Working...
        X