![]() This too involves two commands: generate rep3 = 0 if !missing(rep78) Let’s generate a dummy, rep3, that takes a value of 1 when rep78 is equal to 3. There is another similar but slightly different approach to generating a dummy variable. !missing indicates ‘not missing’, where ‘!’ is an operator for ‘not’. This additional conditional directs Stata to populate rep2 with 0 if there are no missing values in rep78. replace rep2 = 0 if missing(rep2) & !missing(rep78) We shall modify this command to account for missing values in rep78 as well. The (incomplete) command above served to illustrate the importance of being mindful of missing data in relevant variables otherwise data cleaning, variable creation and other data operations will be plagued with data entry and misspecification errors. This is an inaccuracy that needs to be addressed. However, this also means that rep2 takes on a value of 0 when rep78 had missing values (.). It replaces all observations in rep2 with a 0 if rep2 has missing values. This command deals with the missing values generated in rep2. Step 2: replace rep2 = 0 if missing(rep2) ![]() Where rep78 equals 1, 3, 4, 5, rep2 will be populated with missing values (.). This command generates a new variable named ‘rep2’ which takes on the value of 1 only for observations where rep78 is equal to 2. Two-Step Method to Generate Dummy Variable in Stata: Step 1: generate rep2 = 1 if rep78=2 We will explore five methods of generating dummy variables in this article: The option of missing allows us to observe the number of missing values (.) in the variable as well. The tabulate command above allows us to see that the variable is characterised by five categories coded numerically from 1 to 5. To begin with our discussion around dummy variables, let’s observe the variable for repair records in 1978, rep78.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |