Random Assigning Treatment in Stata

306 Views Asked by At

I need help with random assigning treatments in Stata, I am lost. The variable is assigned to be treated with at 45% probability. After the variable has been assigned to be treated, I have to pick the treatment date by randomly drawing a specific time period.

Any help on how to do this. The code I created did not produce any results.

gen effect = runiform(weight,.45)

1

There are 1 best solutions below

0
On BEST ANSWER

The first part of your question, regarding randomly assigning a treatment with 0.45 probability, can be achieved by:

clear
set obs 100
gen id = _n

gen prob = runiform(0,1)

gen     treatment = 0
replace treatment = 1 if prob <= 0.45