Announcement

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

  • DID issue-----how to add industry and fixed effect to diff command

    Hi,

    Does any one know how to add year and industry fixed effect (sum of Year fixed effecti,t) as control variable in diff command?

    I tried to use diff command to execute the DID estimation. However, the general code is: diff y,treat(varname) period(varname) cov(z1 z2) robust

    Then I tried to add i.year and i.industry in as what usually did in normal regression, however, it doesn't work.

    Appreciate in advance!



  • #2
    "doesn't work" is usually not sufficient to get help. Things can not work in a multitude of different ways, and it's hard to help without knowing the details. Good practice is to create an working example demonstrating your problem that anyone can run.

    You should just use the panel model version of DID or create dummies by hand instead of using factor variable notation i. prefix.

    Here's an example with chain fixed effects:

    Code:
    cls
    /* fix sample data */
    use http://fmwww.bc.edu/repec/bocode/c/CardKrueger1994.dta, clear
    drop if id == 407 // duplicate restaurant
    xtset id t
    drop if missing(fte)
    bysort id: keep if _N==2
    
    /* DID */
    reg fte i.treated##i.t bk kfc roys, cluster(id)
    margins, at(t = (0 1) treated = (0 1))
    margins t#treated, nopvalues // opaque syntax, but better labeling of output
    marginsplot                     // graph the effect                    
    margins r.treated#r.t         // calculate DID effect
    
    /* Or like this */
    xtreg fte i.treated##i.t bk kfc roys, fe cluster(id)
    
    
    diff fte, treat(treated) period(t) cov(bk kfc roys) cluster(id)

    Comment


    • #3
      Hi Dimitriy

      Thanks for your help! I'm a new business research student so the codes you posted are complex to me. I found that that the last two code you posted can be replaced by
      diff fte, treat(treated) period(t) cov(bk kfc roys t) cluster(id) and the results are the same. In "help diff", it said cov also used to specify time fixed-effects in the case of multiple time-frequency data (e.g. monthly, yearly, quarterly, etc.). However, I still not sure whether the industry fixed effects can be hold use the same logic.In the example dataset, both industry and year fixed effects are needed. generate treated =(b==1) generate post=(year>=2011) diff csrscore, treat(treated) p(post) cov(size leverage listyear roa slogantimes industry year) robust My question is: do you think industry and firm fixed effects can also be fixed by adding them to the cov(.....)?

      Comment


      • #4
        example dataset is attached in here
        Attached Files

        Comment


        • #5
          If you insist on using -diff-, try this:

          Code:
          tab year, gen(D_year)
          tab industry, gen(D_industry)
          diff y, treat(varname) period(varname) cov(D_industry* D_year*) cluster(id)
          The problem is that -diff- is an older command that does work with the factor variable notation. You need to generate the dummies by hand and pass them to cov() option. In my example, the chain variable got turned into bk, kfc, roys and wendys dummies by whomever put together the restaurants dataset.

          If you want to share your data, use the -dataex- command, along with code that you want to use.

          Comment


          • #6
            Dimitriy

            I've tried your code and I got the results. Thank you, a thousand times!

            Cheers
            Yuhan

            Comment

            Working...
            X