Stata Commands Flashcards
what command lets you observe the data
browse
which command shows what variables we have
desc
what command counts the number of observations satisfying a condition, lets say for observations that are not foreign and also have miles per gallon less than 25
count if foreign != 1 & mpg < 25
what command do you use to summarize the data
sum
how to tabulate a variable to satisfy the condition that the variable is foreign (a binary variable where foreign = 1 when true)
tabulate variablename if foreign == 1
how to generate a new variable
gen newvarname = whateveryouneed
what is the command for observing correlations
corr var1 var2 var3… (as many var as u want)
what is the command for observing covariances
corr var1 var2, cov
what is the command to do a t test on a variable’s mean being 0 as the null hypothesis
ttest varname == 0
the RHS will be whatever your null hypothesis is
how to do a difference in means t test for h0 being 0
use willingness to spend as the variable and employed or unemployed as the binary variable
basically do a t test to test if the difference in willingness to spend is 0 across people who are employed or unemployed
ttest wts, by (employed)
how to run an OLS regression fo only 1 regressor
eg how does willingness to spend change with income
reg wts income
i.e. reg outcome independentvariable
how to create predicted values and then see them
use the regression of income on willingness to spend as example
(directly after a reg command)
predict nameyourvariable
br wts predictvarnameabove income
i.e.
predict nameyourvariable
br outcome varfromabove independentvar
how to create predicted residuals
(directly after reg command)
predict residual, resid
n.b. the word residual is just what u name it not the command
how to create a scatter graph
twoway scatter outcome independentvar
how to plot an OLS reglession line
twoway lfit outcome independentvar
how to make a scatter graph with a regression line through it
twoway (lfit outcome independentvar) (scatter outcome independentvar)
How to name your graph
xtitle(“name”) add this to the end of the graphing command
how to generate a regression table with standard errors to 4dp and beta to 4dp
(reg wts income) this is your regression preceding the command
then type:
outreg2 using reg_output.doc, sdec(4) bdec(4)
you can call the .doc file whatever u want