Last active
October 23, 2019 14:27
-
-
Save bbdaniels/e21401c90896b4a6db64ce063c1804b2 to your computer and use it in GitHub Desktop.
Demo example for [ritest] in Stata
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// [ritest] example | |
// Create randomization program ------------------------------------------------ | |
cap prog drop my_randomization | |
prog def my_randomization | |
syntax , [*] | |
// Must drop the variable for [ritest]. Make sure to keep it saved somewhere | |
cap drop treatment | |
// For demo purpose we do 40%-40-20% randomization | |
xtile temp = runiform() , n(5) | |
qui recode temp /// | |
(1/2=1 "Control")(3/4=2 "Treatment 1")(5=3 "Treatment 2") /// | |
, gen(treatment) | |
lab var treatment "Treatment Assignment" | |
drop temp | |
end // ------------------------------------------------------------------------- | |
// Load data and randomize ----------------------------------------------------- | |
sysuse auto, clear | |
my_randomization | |
ta treatment | |
ritest treatment _b[treatment] /// | |
, samplingprogram(my_randomization) /// | |
kdensityplot : reg price treatment | |
// End of dofile -------------------------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment