SHARE
TWEET

Untitled

a guest Oct 14th, 2019 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. set more off
  2.  
  3.  
  4. use "C:\Users\Anna\Downloads\cmto_seattle.dta",clear
  5.  
  6. *Start a file that will store the estimates
  7. capture postclose rtpf
  8. postfile rtpf s i diff using "C:\Users\Anna\Downloads\rtest.dta" , replace
  9.  
  10.  
  11. *** Question 6
  12.  
  13. * i is the difference between the control
  14. forvalue i= -.2(.01)0.2 {
  15.  
  16. foreach m in leased_up_opp forecast_kravg30_p25 received_cmto_services working black college_plus {
  17.  
  18. *Calculate difference in means (with unequal variances)
  19. reg `m' treatment_group, hc2
  20.  
  21. *Store the difference in means as a local variable
  22. * b[t] is the treatment effect
  23. local b0 = _b[t]
  24.  
  25.  
  26. *Set the seed because we will be generating random variables below
  27. *This makes the analysis re-producible
  28. set seed 2110
  29.  
  30. *Drop variables that will be used in the loop in case they are already defined
  31. cap drop ts
  32. cap drop ys
  33.  
  34. *Calculate fraction of sample that was treated
  35. sum treatment_group
  36. local fractiontreated = r(mean)
  37.  
  38. *Perform 250,000 draws from the assignment vector, storing the difference in means in each run
  39. forv s = 1/100 {
  40.  
  41. *Generate placebo assignment vector based on a Unif r.v., preserving the probability of treatment
  42.  
  43. * ts is our random assignment (what is the probability that this happened by chance)
  44. *treatment_group is what is actually assigned (according to data)
  45.  
  46. gen ts = uniform() <= `fractiontreated'
  47.  
  48. *generate the outcome variable!
  49. g ys =.
  50.  
  51. *Generate outcome variable for the tests below
  52.    
  53.     *Here assuming treatment effects  
  54.     replace ys= `m' - `i' if ts!=treatment_group & treatment_group==1  
  55.     replace ys= `m' + `i' if ts!=treatment_group & treatment_group==0  
  56.    
  57.     *Here assuming simple Fisher null of 0 effects
  58.     replace ys= `m' if ts==treatment_group
  59.  
  60. *Calculate difference in means of ys across placebo treatment group and placebo control group
  61. qui reg ys ts, hc2
  62.  
  63. *Save the iteration number and difference in means
  64. post rtpf ( `s' ) (`i') ( _b[ts] )
  65.  
  66. *Drop variables for next iteration of the loop
  67. drop ts ys
  68.  
  69.  
  70.  
  71. }
  72.  
  73. }
  74.  
  75. *Close and save the "rtest.dta" file
  76. postclose rtpf
  77.  
  78. *Load in "rtest.dta"
  79. use "C:\Users\Anna\Downloads\rtest.dta", clear
  80.  
  81. *Calculate p-value
  82. * b0 is difference/ diff
  83. *i is the treatment effect
  84. g test = (abs( diff) - i >= abs( `b0') - i)
  85.  
  86. *sum by each treatment
  87.  
  88. *count if abs( diff) >= abs( `b0')
  89. loc p = (r(N)+1) / (100+1)
  90. di "rand. test p-val: " `p'
  91.  
  92. }
  93.  
  94. *Close and save the "rtest.dta" file
  95. postclose rtpf
  96.  
  97. *Load in "rtest.dta"
  98. use "C:\Users\Anna\Downloads\rtest.dta", clear
  99.  
  100. *Calculate p-value
  101. * b0 is difference/ diff
  102. *i is the treatment effect
  103. g test = (abs( diff) - i >= abs( `b0') - i)
  104.  
  105. *sum by each treatment
  106.  
  107. *count if abs( diff) >= abs( `b0')
  108. loc p = (r(N)+1) / (100+1)
  109. di "rand. test p-val: " `p'
  110.  
  111. *Generate cumulative CDF
  112. gen absdiff = abs(diff)
  113. cumul absdiff, gen(cdf)
  114.  
  115. *generating a dummy variable and assigning it to p-values that are
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top