Week 3: Hypothesis Testing and Significance Flashcards
What command generates a new variable?
<gen>
</gen>
How do you recode continuous variables into categorical variables?
Use the <recode> or <replace> command in combination with <if> statements to specify ranges and assign categories.
Example:
recode varname (a/b=1) (c/d=2) (e/f=3), gen(newvarname)</if></replace></recode>
Which command labels a variable?
<label variable varname “name”>
How do you ensure the correct categories after recoding a variable?
Use frequency tables and crosstabs, such as <tab></tab>
What is the syntax to assign value labels to a variable?
<label define labelname value1”label1” value2”label2”, replace>
<label></label>
What does the <egen> command do?</egen>
Creates derived variables, such as sums or counts, across specified variables.
What is the purpose of <foreach> and <forvalues> loops?</forvalues></foreach>
They automate repetitive tasks, such as recoding multiple variables
<foreach> is a more general loop that allows string, numeric, and variables as list (without a pattern).
<forvalues> is a more specific loop. Only numeric is allowed as lists, and lists should have a clear pattern.
</forvalues></foreach>
How are missing values assigned in a new variable during coding?
Use <replace varname =. if condition>
How do you combine two categorical variables into one?
Use a combination of logical operators (I, &) and <recode> or <gen> to conditionally create a new variable.
Example:
<gen newvar=.>
<replace newvar=0 if var1==a | var2==b></gen></recode>
<replace> b & var2==c>
etc...
<label variable newvar "Variable name">
<label define newvar1 0"abcd" 1"efgh">
<label>
</label></replace>
What is the syntax to count specific values across multiple variables?
<egen newvar = anycount(varlist), values(value)>
Example: To count number of those with asthma
<egen asthma = anycount (hedib01-hedib06), values(2)>
Here, we know that (2) denotes the presence of asthma in the initial variable
How do you compute the sum of multiple variables into a single variable?
Use <egen newvar = rowtotal(varlist)>
Example:
<egen tot_heart_sum = rowtotal(heart_*)>
What command is used to produce a frequency table?
<tab>
</tab>
What does reverse coding ensure in survey data?
It aligns differently phrased questions for consistent interpretation in scales or indices.
How do you check for errors after creating a new variable?
Cross-tabulate the new variable with its original counterpart and examine discrepancies.
What does the <rowtotal> function in <egen> calculate?</egen></rowtotal>
The sum of specified variables across a row for each observation.