Announcement

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

  • how to create an indictor randomly based on some conditions?

    Dear community members

    How can I create an indicator variable (random) by sorting firms randomly and assigning the first X # of firms to treatment based on how many actual X # firms are treated that year? the indicator will be used in placebo test to ensure the results of my staggered Here is an example of my data: note that magnitude is my DV and treatedxmandate is my IV, and policy in effect indicates the year in which the mandate is passed. Thanks for your kind input.
    input float(magnitude treatedxmandate) into Year float(country_id firm_id policy_in_effect)
    0 0 2009 15 1101 0
    0 0 2014 32 2431 0
    0 0 2009 45 297 0
    0 0 2008 45 297 0
    0 0 2010 45 297 0
    0 0 2016 50 2872 0
    0 0 2015 50 2872 0
    0 0 2017 50 2872 0
    0 0 2019 50 2872 0
    0 0 2016 50 2868 0
    0 0 2016 2 9 0
    0 0 2017 2 9 0
    0 0 2012 37 2530 0
    0 0 2013 37 2530 0
    0 0 2016 45 295 0
    0 0 2013 3 39 0
    0 0 2015 3 39 0
    0 0 2017 50 3275 0
    0 0 2018 45 295 0
    0 0 2011 42 1875 0
    0 0 2006 49 919 0
    0 0 2010 42 1875 0

  • #2
    Something is wrong. You say that the variable policy_in_effect indicates the year in which the mandate is passed, but that is clearly not true. In fact policy_in_effect isn't a variable at all: it's just zero.

    What you want to do cannot be done without knowing the year the mandate went into effect for each firm. If it is the same for all firms, just say what year that is. If it varies across firms, then it needs to be a variable in the data.

    Comment


    • #3
      Hi Clyde
      Thanks for your response. The variable policy_in_effect is not always zero, the data I posted earlier just happened to contain zero for the listed observations above. Here is a better data example:
      input float(magnitude treatedxmandate) int Year float(firm_id treated policy_in_effect):note that magnitude is my DV and treatedxmandate is my IV, and policy in effect indicates the year in which the mandate is passed
      .57 0 2018 1 1 1
      .57 0 2019 1 0 0
      .46 0 2019 2 0 0
      .74 0 2017 2 1 1
      .56 0 2016 2 0 0
      .95 0 2014 2 1 1
      .95 0 2015 2 0 0
      .96 0 2013 2 0 0
      .67 0 2018 2 1 1
      .65 0 2009 3 0 0
      .46 0 2017 3 0 0
      .45 0 2018 3 1 1
      .86 0 2015 3 1 1
      .45 0 2019 3 0 0
      .89 0 2012 3 1 1
      .9 0 2016 3 0 0
      .89 0 2011 3 1 1
      .51 0 2005 3 0 0
      .88 0 2010 3 0 0
      .71 0 2008 3 1 1
      .63 0 2007 3 1 1
      .86 0 2013 3 1 1
      .55 0 2006 3 0 0
      .85 0 2014 3 1 1
      .99 0 2017 4 0 0
      .98 0 2015 4 0 0
      .99 0 2018 4 0 0
      .99 0 2019 4 0 0
      .98 0 2014 4 0 0
      .98 0 2016 4 0 0
      Thank you for your kind help.

      Comment


      • #4
        OK. So this is more complicated than I expected. I see that this is not a simple (generalized) DID setup: the policy can go in effect, and then go out of effect, and then come back in. And some firms never have the policy in effect. Even this could be easily overcome if all firms were observed for the same years, but that is also clearly not the case.

        Ordinarily, in a simpler situation without so many complications, I would simply randomly reassign the values of policy_in_effect over the years to other firms at random. But given that different firms are represented in the data in different time intervals, this is not possible. What is possible is to simply reassign random value to the policy_in_effect variables--but this would destroy so much of the structure in the data that it seems to me too radical to be a valid placebo test. I can't imagine how even a completely bogus analysis could fail to be "vindicated" by such a radical "placebo" test.

        I don't really know what to do in this situation. Perhaps somebody else following along can contribute a solution. Sorry I can't be more helpful.

        Comment


        • #5
          Thanks, Clyde for your attempts anyway.

          Comment

          Working...
          X