Announcement

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

  • struggling with creating a placebo test for stgarred DID estimated model

    Hi community

    I have posted here before without getting any help and I am posting again to seek your kind help on the following :
    - I need to create an indicator variable by sorting firms randomly and assigning the first X # of firms to treatment based on how many actual X # firms are treated that year.
    so suppose the number of treated firms in 2005 = 50, I would like to randomly assign the first 50 firms in 2005 as treated, and the same goes for all the years. how can I code this in Stata, please?

    Here are descriptions of my variables below: magnitude is my DV, treatedxmadnate is my IV, policey_in _effect refers to a dummy = one once the country mandates a policy during a given year and remains one for the future years, and zero otherwise. treated x mandate refers to firms effected by the mandate. Policey1year refers to the first year a country mandates the policy.
    input str44 Country int Year float(firm_id magnitude treatedxmandate policy_in_effect) int Policy1Year
    "United States" 2019 3062 1.6 0 0 .
    "Brazil" 2011 216 .74 0 0 .
    "New Zealand" 2013 2420 1.11 0 0 .
    "Hong Kong" 2019 137 .6 1 1 2014
    "South Korea" 2013 1866 .63 1 1 2012
    "Japan" 2019 1766 .590 1 1 2005
    "United States" 2012 2965 .95 0 0 .
    "Japan" 2007 1344 .83 1 1 2005
    "United States" 2006 2832 .93 0 0 .
    "Sweden" 2007 2631 .429 1 1 2005
    "South Korea" 2017 1828 .32 1 1 2012
    "Switzerland" 2016 319 .48 0 0 .
    "Sweden" 2013 2572 .47 1 1 2005

    I appreciate your help.

  • #2
    I send you one option by email, but the following may also work:

    Code:
    frause mpdta, clear
    bysort countyreal:gen flag=_n==1
    gen r=runiform()
    sort flag r
    bysort flag:gen ind=_n if flag==1
    bysort countyreal:egen final_ind = max(ind*(flag==1))
    gen placebo=0 if inrange(ind,0,309)
    replace placebo=2004 if inrange(ind,310,329)
    replace placebo=2006 if inrange(ind,330,369)
    replace placebo=2007 if inrange(ind,369,500)
    Now you say you are new to Stata, so you may want to learn some of data management and data cleaning commands.
    What I provide above is just one option for what you want, but if you can probably come up with something easier or faster. But will require a bit more thought

    HTH
    Fernando

    Comment


    • #3
      Hi Fernando

      Thanks for your kind help and insights. I have two questions if I may: one is how did you determine the range for each year? for example, replace placebo=2004 if in range(ind,310,329). The second question is why do I need to merge the placebo test into my current dataset?

      thank you again for your time and help.

      Comment


      • #4
        The rangers are based on my data
        juat count how many belong to each group
        and in the other code, merge was requieres so you have that placebo in your data

        Comment


        • #5
          I am grateful for your insights and guidance, Fernando so thank you so much.

          Comment

          Working...
          X