Skip to main content area Skip to institutional navigation Skip to sub-navigation

Stata Video Tutorials

Webpage Contents (navigate to the section you need)

Note: Example commands are included in some cases. Simply replace italicized words with your variables.

    • catvar = categorical variable
    • groupvar = grouping (categorical) variable
    • intvar = interval variable
    • indvar = independent variable
    • depvar = dependent variable 

ACCESSING STATA (return to contents)


ENTERING OR IMPORTING DATA (return to contents)


DATA MANAGEMENT AND PREP (return to contents)

  • Know your data
    • codebook var1 var2
  • Do-files
  • Changing variable names from upper to lower case (and vice versa)
    • varcase
  • Cloning a variable and renaming a variable
    • clonevar newvar = oldvar
    • rename oldvarname newvarname
  • Recoding categorical variables(e.g., creating dummies; reordering response categories)
    • recode catvar ("label1")("label2"), generate(newvar) label(newvar) test
    • recode catvar (#/# = "label1")(# # "label2"), generate(newvar) label(newvar) test
    • tabulate catvar, gen(catvar) [this generates dummies from a categorical variable]
  • Reverse coding categorical variables
    • revrs var
  • Changing numeric values in other data formats (e.g., -9) to Stata's version of missing values (.) 
    • mvdecode _all, mv(-9)
    • mvdecode var, mv(-9)
  • Adding variable and value labels
  • Generating new variables from existing variables
  • Creating a composite variable
    • Start by recoding variables as needed (intuitive directions, etc.)
    • Decide whether items will need to be standardized due to varying value sets, then:
      • alpha var1 var2 var3 var4, item
        • or
      • alpha var1 var2 var3 var4, std item
    • Decide which variables should be included in the final composite by examining the alpha scores. Then you can use the alpha command to actually generate the new composite variable. Notice that, assuming you want to base the composite on the mean value of the components, that you can set a minimum number of values that must be present before a composite is calculated (e.g., 2 of the set).
      • alpha var1 var2 var3, gen(compvar) min(2)
        • or
      • alpha var1 var2 var3, gen(compvar) min(2) std
    • If all of your variables share the same value set, then no standardization is needed. You then have the option of either basing the composite on the mean of those values, or adding them up. If you add them up (rowtotal), be sure to calculate a composite for only those cases that have no missing values for any of the component variables. Instead of using the alpha command to generate the variable, you'll need to first create a variable that counts up the number of missing values for your cases with respect to the component variables. You can then use that variable to set the condition that a composite be calculated only for those cases with no missing values.
      • egen float compmiss = rowmiss(var1 var2 var3)
      • tab compmiss
      • egen float compvar = rowtotal(var1 var2 var3) if compmiss==0




BIVARIATE ANALYSES (return to contents)

Cross-tabulations and Chi-Squared (return to contents)

T-tests (return to contents)

ANOVA (return to contents)
  • One-way analysis of variance(including Bonferroni test and effect size measure)
    • oneway intvar catvar, tabulate bonferroni
    • If looking for a measure of effect size, run the following ANOVA command; it provides an R-squared:
      • anova intvar catvar
  • See Box Plot video to see a complementary graphing option for ANOVA
  • Kruskal-Wallis rank test (nonparametric alternative to ANOVA)
    • kwallis var, by(catvar)

Correlation and Simple Regression (return to contents)


MULTIVARIATE ANALYSES (return to contents)

Multiple OLS Regression (return to contents)

  • Multiple OLS regression
    • regress depvar indvar1 indvar2 
    • regress depvar indvar1 indvar2, beta
    • regress depvar indvar1 indvar2, robust [if concerns about normality of depvar]
    • nestreg: regress depvar (1stvar) (2ndvar) (3rdvar 4thvar)
  • Semipartial correlations
    • pcorr2 depvar indvar1 indvar2 indvar3
  • Regression diagnostics -- Checking for Multicollinearity and Outliers
    • Calculating Cook's to identify influential cases (outliers):
      • predict cooksd, cooksd
      • list id cooksd if cooksd > 4/n
    • Checking for multicollinearity
      • estat vif
  • Adjusting for sampling weights
    • regress depvar indvar1 indvar2 [pweight = weightvar]

Multiviarate Logistic Regression (return to contents)

  • Logistic regression
    • logistic depvar indvar1 indvar2
    • listcoef, help percent
    • nestreg: logistic depvar (1stvar) (2ndvar) (3rdvar 4thvar)
  • Graphing odds ratios
  • Calculating predicted probabilities
  • Ordered logistic regression
    • ologit depvar indvar1 indvar2