Skip to content

Instantly share code, notes, and snippets.

@bbdaniels
Last active January 13, 2020 18:12
Show Gist options
  • Save bbdaniels/bee9a0eed86d9043d2ad0447c152ca4a to your computer and use it in GitHub Desktop.
Save bbdaniels/bee9a0eed86d9043d2ad0447c152ca4a to your computer and use it in GitHub Desktop.
Simulation: Big and small effects from RCTs
// Simulation 1: Big effects from small RCTs
cap mat drop results
qui forv iter = 1/1000 {
clear
set obs 10000
gen x = rnormal() > 0
gen e = rnormal() * 4
gen y = 5 + 0*x + e
reg y x
mat temp = r(table)
mat result = temp[....,1]
mat result = result'
mat results = nullmat(results) ///
\ result
}
clear
svmat results , n(col)
// End of dofile
// Simulation 2: Small effects from measurement errors
cap mat drop results
qui forv iter = 1/1000 {
clear
set obs 10000
gen x = runiform() * 100
gen me = rnormal() * 50
gen temp = x + me
gen x_obs = max(temp,0)
gen e = rnormal() * 4
gen y = 5 + 20*x + e
reg y x
mat temp = r(table)
mat result = temp[....,1]
mat result = result'
mat results = nullmat(results) ///
\ result
}
clear
svmat results , n(col)
// End of dofile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment