Announcement

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

  • Staggered Diff-in-Diff using Stata

    So, I am trying to estimate the effect of contract enforcement on debt maturity (independent var on dep var) using a staggered difference-in-differences specification. The idea is that contract enforcement was introduced in different states on different years. The Dataset includes different codes for different states, different codes for different companies (within a specific state), independent variables and year as a variable for years.

    As Follows:

    https://ibb.co/JBCV2wM

    As previously mentioned, different groups of states have different treatment years. Some states got treated (law passed) starting 1995, others starting 1997, 2000 and 2005. So, essentially we got 4 treatment timelines for different states. As follows: https://ibb.co/M6qgvwD

    The task is to calculate the staggered diff-in-diff coefficient for treatment in general!

    I started by sorting the dataset using:
    sort st_code year
    I then created dummy variables for all states and all years so that i can account for state fixed effects and time fixed effects (as far as i am aware):
    tabulate st_code , generate(statedummy) tabulate year , generate(yeardummy)
    The most important step was to create the treated variable in order to be able to carry out the regression, i did this using the following code: (the conditions correspond to the year of treatment for each state in the dataset)
    generate Treated = statedummy1==1 if year >= 1995
    replace treated = 1 if ((st_code==3 & year>=1997) | (st_code==4 & year>=1997) | (st_code==5 & year>=1997) | (st_code==6 & year>=1995) | (st_code==8 & year>=1995) | (st_code==9 & year>=1995) | (st_code==10 & year>=1995) | (st_code==11 & year>=2000) | (st_code==12 & year>=1995) | (st_code==13 & year>=1995) | (st_code==14 & year>=1995) | (st_code==17 & year>=1995) | (st_code==18 & year>=1997) | (st_code==19 & year>=1999) | (st_code==20 & year>=2000) | (st_code==22 & year>=1997) | (st_code==26 & year>=1997) | (st_code==27 & year>=1997) | (st_code==29 & year>=1997) | (st_code==30 & year>=1995) | (st_code==31 & year>=1995) | (st_code==33 & year>=1997) | (st_code==36 & year>=1999) | (st_code==37 & year>=1999) | (st_code==38 & year>=1995))
    However, when i tried carrying out the regression using this code:
    xtreg Longtermdebt_to_totalassets_w treated i.st_code i.year, cluster( st_code )
    I kept getting errors. I even tried using different versions or just a reg command but Stata wouldn't let me.

    So, I would really appreciate it, if someone would point out what i did wrong or where things went bad.

  • #2
    I think your question has gone unanswered for over 12 hours because it does not contain enough information to provide an answer, and some aspects of it are confusing.

    Saying you are "getting errors" without explaining just what those errors are is just not informative enough for anybody to help. Saying you "tried using different versions" without showing the actual versions is also not enough for anybody to help. Also, an -xtreg- command cannot be fully understood without knowing how you -xtset- your data before that. It is also almost always a good idea to show example data when asking for help with code since the problem is just as likely to be in the data as it is in the code.

    So I suggest you post back showing the actual error messages you are getting, the actual code you have tried, and an example of your data set. Use the -dataex- command to show the example data so it will be usable by those who want to help. And be sure to choose an example that actually illustrates the problem(s) you are encountering.

    If you are running version 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    When asking for help with code, always show example data. When showing example data, always use -dataex-.

    Comment


    • #3
      I did repost it and tried to clarify a bit on my issues here: https://www.statalist.org/forums/for...ces-%7C-repost

      Thank you for your advice!

      Comment

      Working...
      X