SHARE

TWEET

# Untitled

a guest
Oct 14th, 2019
78
Never

**Not a member of Pastebin yet?**

**, it unlocks many cool features!**

__Sign Up__- set more off
- use "C:\Users\Anna\Downloads\cmto_seattle.dta",clear
- *Start a file that will store the estimates
- capture postclose rtpf
- postfile rtpf s i diff using "C:\Users\Anna\Downloads\rtest.dta" , replace
- *** Question 6
- * i is the difference between the control
- forvalue i= -.2(.01)0.2 {
- foreach m in leased_up_opp forecast_kravg30_p25 received_cmto_services working black college_plus {
- *Calculate difference in means (with unequal variances)
- reg `m' treatment_group, hc2
- *Store the difference in means as a local variable
- * b[t] is the treatment effect
- local b0 = _b[t]
- *Set the seed because we will be generating random variables below
- *This makes the analysis re-producible
- set seed 2110
- *Drop variables that will be used in the loop in case they are already defined
- cap drop ts
- cap drop ys
- *Calculate fraction of sample that was treated
- sum treatment_group
- local fractiontreated = r(mean)
- *Perform 250,000 draws from the assignment vector, storing the difference in means in each run
- forv s = 1/100 {
- *Generate placebo assignment vector based on a Unif r.v., preserving the probability of treatment
- * ts is our random assignment (what is the probability that this happened by chance)
- *treatment_group is what is actually assigned (according to data)
- gen ts = uniform() <= `fractiontreated'
- *generate the outcome variable!
- g ys =.
- *Generate outcome variable for the tests below
- *Here assuming treatment effects
- replace ys= `m' - `i' if ts!=treatment_group & treatment_group==1
- replace ys= `m' + `i' if ts!=treatment_group & treatment_group==0
- *Here assuming simple Fisher null of 0 effects
- replace ys= `m' if ts==treatment_group
- *Calculate difference in means of ys across placebo treatment group and placebo control group
- qui reg ys ts, hc2
- *Save the iteration number and difference in means
- post rtpf ( `s' ) (`i') ( _b[ts] )
- *Drop variables for next iteration of the loop
- drop ts ys
- }
- }
- *Close and save the "rtest.dta" file
- postclose rtpf
- *Load in "rtest.dta"
- use "C:\Users\Anna\Downloads\rtest.dta", clear
- *Calculate p-value
- * b0 is difference/ diff
- *i is the treatment effect
- g test = (abs( diff) - i >= abs( `b0') - i)
- *sum by each treatment
- *count if abs( diff) >= abs( `b0')
- loc p = (r(N)+1) / (100+1)
- di "rand. test p-val: " `p'
- }
- *Close and save the "rtest.dta" file
- postclose rtpf
- *Load in "rtest.dta"
- use "C:\Users\Anna\Downloads\rtest.dta", clear
- *Calculate p-value
- * b0 is difference/ diff
- *i is the treatment effect
- g test = (abs( diff) - i >= abs( `b0') - i)
- *sum by each treatment
- *count if abs( diff) >= abs( `b0')
- loc p = (r(N)+1) / (100+1)
- di "rand. test p-val: " `p'
- *Generate cumulative CDF
- gen absdiff = abs(diff)
- cumul absdiff, gen(cdf)
- *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.