Announcement

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

  • Generating treatment variable for diff-in-diff

    Dear Statalisters,

    Once again, I need your expert advice and help. I am doing a difference-in-difference estimation and I'm struggling with the creation of the treated variable. My dataset follows individuals for years 2007 and 2009 (pre-treatment and post-treatment).

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long Personnalnumber int year float(laborcontract2007 laborcontract2009 openended2009) byte laborcontract
    100501 2007 1 . 0 1
    100501 2009 . 4 0 4
    101401 2007 2 . 0 2
    101401 2009 . 2 1 2
    102501 2007 6 . 0 6
    102501 2009 . 6 0 6
    102502 2009 . 6 0 6
    102502 2007 2 . 0 2
    103101 2009 . 3 0 3
    103101 2007 4 . 0 4
    103102 2009 . 3 0 3
    103102 2007 4 . 0 4
    103301 2007 3 . 0 3
    103301 2009 . 2 1 2
    103501 2009 . 2 1 2
    103501 2007 2 . 0 2
    103901 2009 . 1 1 1
    103901 2007 1 . 0 1
    103902 2007 1 . 0 1
    103902 2009 . . 0 .
    103903 2007 1 . 0 1
    103903 2009 . . 0 .
    105201 2009 . 2 1 2
    105201 2007 3 . 0 3
    105301 2009 . 6 0 6
    105301 2007 1 . 0 1
    105701 2007 2 . 0 2
    105701 2009 . 1 1 1
    105801 2007 6 . 0 6
    105801 2009 . 6 0 6
    105802 2007 6 . 0 6
    105802 2009 . 6 0 6
    106101 2009 . 6 0 6
    106101 2007 6 . 0 6
    106102 2007 6 . 0 6
    106102 2009 . 7 0 7
    106301 2007 2 . 0 2
    106301 2009 . 4 0 4
    107001 2007 2 . 0 2
    107001 2009 . . 0 .
    107002 2009 . 2 1 2
    107002 2007 1 . 0 1
    107101 2009 . 2 1 2
    107101 2007 2 . 0 2
    107102 2007 1 . 0 1
    107102 2009 . . 0 .
    end

    I want to generate a variable that considers treated individuals that have switched from having no labor contract in 2007 (laborcontract2007=4 or laborcontract2007=3) to having an open-ended labor contract in 2009 (openended2009=1) and taking self-employed people (labor contract=6) as a control group.

    I tried by doing this:
    Code:
    gen treated= laborcontract2007==3|laborcontract2007==4 & openended2009
    replace treated=. if laborcontract2009==3| laborcontract2009==4| laborcontract2009==7
    
    replace treated=1 if laborcontract2007==3|laborcontract2007==4|laborcontract2007==7|laborcontract2007==9|laborcontract2007==11|laborcontract2007==12 & laborcontract2009==1|laborcontract2009==2
    However, looking into the dataset after running this, I can see that treated individuals are not well identified (some are not included and some individuals that should be treated are not). I think I'm missing something and not coding my treatment variable correctly. Could you guys point me in the right direction?

    Thank you very much, your help is highly appreciated!

  • #2
    I want to generate a variable that considers treated individuals that have switched from having no labor contract in 2007 (laborcontract2007=4 or laborcontract2007=3) to having an open-ended labor contract in 2009 (openended2009=1)
    Code:
    sort Personnalnumber year
    by Personnalnumber: egen hasopen09=max(openended2009)
    by Personnalnumber: egen treated= max(cond(inlist(laborcontract2007, 3,4)& hasopen09, 1, 0 ))

    Comment


    • #3
      Andrew-

      Thank you so much! It works great! Looks like I need to look at the
      Code:
      egen
      command in more detail. Thanks a lot

      Comment

      Working...
      X