Difference between revisions of "Randomization in Stata"
Mrijanrimal (talk | contribs) |
|||
Line 1: | Line 1: | ||
This page describes how and why to use Stata for randomization of control and treatment assignment in an RCT. Common alternatives to using Stata for randomization include: (i) Using the Excel command; (ii) Randomizing directly within a chosen electronic survey platform such as SurveyCTO; or (iii) randomization through a public lottery. | |||
== Why use Stata to randomize == | == Why use Stata to randomize == | ||
Using Stata to randomize and then preloading the generated data file into the survey software is the | Using Stata to randomize and then preloading the generated data file into the survey software is generally preferred to using Excel or randomizing within the electronic platform. The main advantages of using Stata for randomization are as follows: | ||
* | * The process is transparent and reproducible. | ||
* | * The researcher has more control of the process, allowing you to check randomization balance and add stratification variables if needed. | ||
* Since randomization in Stata is done before the survey takes place (as opposed to randomization through the survey platform. This provides an opportunity to double check the result of a randomization and fix bugs before using the software in the field. | |||
==Steps needed for replicability when randomizing in Stata == | ==Steps needed for replicability when randomizing in Stata == | ||
Line 11: | Line 11: | ||
Here are a few steps that should be followed to create a reproducible randomization using Stata: | Here are a few steps that should be followed to create a reproducible randomization using Stata: | ||
* | * Make sure your dataset includes a unique ID [respondent ID, household number, etc.]. If one doesn't exist yet, you can create one using the XX command. | ||
* While writing a do-file, pay close attention to the following things: | * While writing a do-file, pay close attention to the following things: | ||
** Set version. Setting Stata's version in a do file ensures that the randomization algorithm is the same, | ** Set version. Setting Stata's version in a do file ensures that the randomization algorithm is the same, since the algorithm sometimes changes between Stata versions. </br> For example - <code> version 12.0 </code> | ||
** Set seed. This makes sure that the same random number is generated for the first observation, for the second observation, and so on, for every time the code is run. </br> For example - <code> set seed 12345 </code> | ** Set seed. This makes sure that the same random number is generated for the first observation, for the second observation, and so on, for every time the code is run. </br> For example - <code> set seed 12345 </code> | ||
** Properly sorting the data. The data should be sorted such that observations are in the same order every time the code is run. The most optimal situation is sorting using an ID variable which uniquely and fully identifies each observation. | ** Properly sorting the data. The data should be sorted such that observations are in the same order every time the code is run. The most optimal situation is sorting using an ID variable which uniquely and fully identifies each observation. | ||
Line 23: | Line 23: | ||
The steps to randomize in Stata with stratification is as follows: | The steps to randomize in Stata with stratification is as follows: | ||
== Randomization with Multiple Treatment Arms == | |||
== Back to Parent == | == Back to Parent == |
Revision as of 19:49, 7 February 2017
This page describes how and why to use Stata for randomization of control and treatment assignment in an RCT. Common alternatives to using Stata for randomization include: (i) Using the Excel command; (ii) Randomizing directly within a chosen electronic survey platform such as SurveyCTO; or (iii) randomization through a public lottery.
Why use Stata to randomize
Using Stata to randomize and then preloading the generated data file into the survey software is generally preferred to using Excel or randomizing within the electronic platform. The main advantages of using Stata for randomization are as follows:
- The process is transparent and reproducible.
- The researcher has more control of the process, allowing you to check randomization balance and add stratification variables if needed.
- Since randomization in Stata is done before the survey takes place (as opposed to randomization through the survey platform. This provides an opportunity to double check the result of a randomization and fix bugs before using the software in the field.
Steps needed for replicability when randomizing in Stata
Here are a few steps that should be followed to create a reproducible randomization using Stata:
- Make sure your dataset includes a unique ID [respondent ID, household number, etc.]. If one doesn't exist yet, you can create one using the XX command.
- While writing a do-file, pay close attention to the following things:
- Set version. Setting Stata's version in a do file ensures that the randomization algorithm is the same, since the algorithm sometimes changes between Stata versions.
For example -version 12.0
- Set seed. This makes sure that the same random number is generated for the first observation, for the second observation, and so on, for every time the code is run.
For example -set seed 12345
- Properly sorting the data. The data should be sorted such that observations are in the same order every time the code is run. The most optimal situation is sorting using an ID variable which uniquely and fully identifies each observation.
- Set version. Setting Stata's version in a do file ensures that the randomization algorithm is the same, since the algorithm sometimes changes between Stata versions.
- Convert the random numbers into categorical variables or dummy variables. This helps you check if the data is balanced.
The end goal is to have a CSV format file containing the ID variable used for randomization and the categorical variables created from the random numbers generated. This dataset will be preloaded into SurveyCTO, so that after an enumerator enters the respondent ID at the start of a survey, the result of the randomization will be loaded for the form and can be used for various sections of the survey.
Randomization with Stratification in Stata
The steps to randomize in Stata with stratification is as follows:
Randomization with Multiple Treatment Arms
Back to Parent
This article is part of the topic Randomized Control Trials