Things I Love About Stata — egen mean

egen mean I work a lot with clustered data, including group psychotherapy data (people clustered in groups), individual psychotherapy data (people clustered within therapists), and longitudinal data (observations clustered within people). Consequently, I often need to create cluster-level means and grand means for graphing and modeling. The egen mean function makes creating means easy. CombiningContinue reading “Things I Love About Stata — egen mean”

Stata: Using generate to create new variables

The primary method for creating new variables in Stata is the generate command. Load the auto dataset. New Variable from Existing Variables Let’s create a new variable that is the sum of weight and length (ignore for the moment that summing weights and lengths doesn’t make a ton of sense). The syntax of generate is:Continue reading “Stata: Using generate to create new variables”

Stata: Predicted Scores and Residuals

Predicted Scores in Stata As we discussed in class, the predicted value of the outcome variable can be created using the regression model. For example, we can use the auto dataset from Stata to look at the relationship between miles per gallon and weight across various cars. We estimate the follow equation Thus, we seeContinue reading “Stata: Predicted Scores and Residuals”

Stata: Dummy Coding

This post will illustrate how to: Use the generate and replace commands to create dummy variables. A second use of the generate command to create dummy variables that is simpler that #1. Using tabluate to create dummy variables. Dummy coding is used when you have nominal categories, meaning the groups are assigned a value forContinue reading “Stata: Dummy Coding”

Stata: Labeling & Recoding Data

Labeling Data In order to assign labels to values of your variable, you can use either the variables manager or command syntax. For example, if you wanted to assign labels to each condition, where 1 represents No treatment, 2 represents Treatment A, 3 represents Treatment B, and 4 represents Treatment C, you could double-click onContinue reading “Stata: Labeling & Recoding Data”

Stata: Do-files and Log-files

As you begin to work with datasets, there are two record and save your commands and actions in Stata. Creating do-files Do-files allow you to record all of your commands. There are a number of benefits to using do-files. By using do-files to run your commands, you have a copy of what you did, whichContinue reading “Stata: Do-files and Log-files”

Stata: Planned Comparisons with the test command

This post will show you how to: Run a one-way ANOVA using an independent variable with four levels. Use planned comparisons to contrast levels of the independent variable. We will use the built-in dataset systolic. Examining the data We will treat the systolic variable as the outcome and drug as the independent variable. Let’s lookContinue reading “Stata: Planned Comparisons with the test command”

Stata: Reading in Comma Separated Files

This post will show how to read in comma separated files (also known as .csv files) into Stata. I will show you how to use both syntax and point-and-click. Syntax You can import csv files using the insheet command. The using auto.csv statement just tells Stata the file name of the csv file. If theContinue reading “Stata: Reading in Comma Separated Files”