Skip to content

Instantly share code, notes, and snippets.

@bbdaniels
Last active October 23, 2019 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bbdaniels/e21401c90896b4a6db64ce063c1804b2 to your computer and use it in GitHub Desktop.
Save bbdaniels/e21401c90896b4a6db64ce063c1804b2 to your computer and use it in GitHub Desktop.
Demo example for [ritest] in Stata
// [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