Announcement

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

  • Creating time to treat period for event study analysis part 2

    Hello,

    I am having an issue with my data. I have created a simple example data set here:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(Family_id Year had_new_kid Wanted)
    1 2000    . 2001
    2 2000    .    .
    3 2000    .    .
    4 2000 2000 2000
    5 2000    . 2002
    1 2001 2001 2001
    2 2001    .    .
    3 2001    .    .
    4 2001    . 2000
    5 2001    . 2002
    1 2002    . 2001
    2 2002    .    .
    3 2002    .    .
    4 2002    . 2000
    5 2002 2002 2002
    1 2003    . 2001
    2 2003    .    .
    3 2003    .    .
    4 2003 2003 2000
    5 2003    . 2002
    end

    Here, I have a panel data set on five families from years 2000 to 2002. Now, I have the year when they have their first kid. Now, I want to run an event study analysis, where I have to create leads and lags period for the families after and from having the first kid. Therefore, I need to create time to treat variables. I got that variable listed as "wanted" here using the following code:

    Code:
    bys Family_id (had_new_kid): gen wanted= had_new_kid[1]
    I am having another problem here! Please have a look at the data set above; notice that family_id 4 had kid again at year 2003. Can the previous code still generate the year when they have their first kid? which would still be 2000. In this case I tried the code mentioned above, it worked! However, I still need to determine the families like 4 here, which had kids more than once.

    Thank you so much!




  • #2
    Here is how you can tag such families. I also show how to generate a count of how many times a family had a kid or kids. Note that you cannot use this variable to represent the number of kids because a birth can involve twins, triplets and so on.

    Code:
    isid Family_id Year
    bys Family_id: egen frequency= total(!missing(had_new_kid)) 
    by Family_id: gen two_or_more= freq>1
    Res.:

    Code:
    . l, sepby(Fam)
    
         +-----------------------------------------------------------+
         | Family~d   Year   had_ne~d   Wanted   freque~y   two_or~e |
         |-----------------------------------------------------------|
      1. |        1   2002          .     2001          1          0 |
      2. |        1   2001       2001     2001          1          0 |
      3. |        1   2003          .     2001          1          0 |
      4. |        1   2000          .     2001          1          0 |
         |-----------------------------------------------------------|
      5. |        2   2000          .        .          0          0 |
      6. |        2   2003          .        .          0          0 |
      7. |        2   2001          .        .          0          0 |
      8. |        2   2002          .        .          0          0 |
         |-----------------------------------------------------------|
      9. |        3   2003          .        .          0          0 |
     10. |        3   2001          .        .          0          0 |
     11. |        3   2000          .        .          0          0 |
     12. |        3   2002          .        .          0          0 |
         |-----------------------------------------------------------|
     13. |        4   2003       2003     2000          2          1 |
     14. |        4   2001          .     2000          2          1 |
     15. |        4   2000       2000     2000          2          1 |
     16. |        4   2002          .     2000          2          1 |
         |-----------------------------------------------------------|
     17. |        5   2002       2002     2002          1          0 |
     18. |        5   2000          .     2002          1          0 |
     19. |        5   2001          .     2002          1          0 |
     20. |        5   2003          .     2002          1          0 |
         +-----------------------------------------------------------+

    Comment


    • #3
      Thanks a lot, Andrew Musau!!

      Comment

      Working...
      X