guest contributer

Getting Started with Stata Tutorial #6: How Stata Code Works

July 18th, 2024 by

If you’ve tried coding in Stata, you may have found it strange. The syntax rules are straightforward, but different from what I’d expect.

I had experience coding in Java and R before I ever used Stata. Because of this, I expected commands to be followed by parentheses, and for this to make it easy to read the code’s structure.

Stata does not work this way.

An Example of how Stata Code Works

To see the way Stata handles a linear regression, go to the command line and type

h reg or help regress

You will see a help page pop up, with this Syntax line near the top.

(If you need a refresher on getting help in Stata, watch this video by Jeff Meyer.)

This is typical of how Stata code looks. (more…)


Member Training: Introduction to Structural Equation Modeling

June 1st, 2024 by

Structural Equation Modeling (SEM) is a popular method to test hypothetical relationships between constructs in the social sciences. These constructs may be unobserved (a.k.a., “latent”) or observed (a.k.a., “manifest”).

In this training, you will learn the different types of SEM: confirmatory factor analysis, path analysis for manifest and latent variables, and latent growth modeling (i.e., the application of SEM on longitudinal data).

We’ll discuss the different terminology, the commonly used symbols, and the different ways a model can be specified, as well as how to present results and evaluate the fit of the models.

This training will be at a very basic conceptual level; however, it is assumed that participants have an understanding of multiple regression, interpretation of statistical tests, and methods of data screening.


Note: This training is an exclusive benefit to members of the Statistically Speaking Membership Program and part of the Stat’s Amore Trainings Series. Each Stat’s Amore Training is approximately 90 minutes long.

(more…)


Getting Started with Stata Tutorial #5: The Stata Do-File

May 4th, 2024 by

From our first Getting Started with Stata posts, you should be comfortable navigating the windows and menus of Stata. We can now get into  programming in Stata with a do-file.

Why Do-Files?

A do-file is a Stata file that provides a list of commands to run. You can run an entire do-file at once, or you can highlight and run particular lines from the file.

If you set up your do-file correctly, you can just click “run” after opening it. The do-file will set you to the correct directory, open your dataset, do all analyses, and save any graphs or results you want saved.

I’ll start off by saying this: Any analysis you want to run in Stata can be run without a do-file, just using menus and individual commands in the command window. But you still should make a do-file for the following reason:

Reproducibility (more…)


Too Many Colors Spoil the Graph

March 26th, 2024 by

When you draw a graph- either a bar chart, a scatter plot, or even a pie chart, you have the choice of a broad range of colors that you can use. R, for example, has 657 different colors from aliceblue to yellowgreen. SAS has 13 shades of orange, 33 shades of blue, and 47 shades of green. They even have different shades of black.

You have a wealth of colors, but you can’t use all of them in the same graph. The ideal number of colors is 2.

(more…)


Getting Started with Stata Tutorial #4: the Statistics Menu

February 4th, 2024 by

In part 3 of this series, we explored the Stata graphics menu. In this post, let’s look at the Stata Statistics menu.

Statistics Menu

statistics tab

Let’s use the Statistics menu to see if price varies by car origin (foreign).

We are testing whether a continuous variable has a different mean for the two categories of a categorical variable. So we should do a 2-sample t-test.

Say we want to use a 90% confidence level, and we have reason to suspect the two groups have unequal variance.

Click Statistics -> Summaries, tables, and tests -> Classical tests of hypothesis -> t test (mean-comparison test).

We want a Two-sample using groups. Put “price: for Variable name and “foreign” for Group variable name.

We click the Unequal variances button in the Main tab to make the variances of the two groups distinct, then change the Confidence level to 90%, and press OK.

Stata outputs the following code:

ttest price, by(foreign) unequal level(90)

and the following table:

table

This statistics tab can be used for all sorts of tests and analysis, such as regressions, generalized linear models, variable summaries, z-tests, and much more. Go ahead and look through the menu to get an idea of what’s available.

But now that you know how to use the menus, we’re not going to use them much in the rest of this series.

As a general rule, it is typically better to use do-files for our analysis, and only use the menus for helping to find the right code to put into our do-files.

by James Harrod

About the Author:
James Harrod interned at The Analysis Factor in the summer of 2023. He plans to continue into a career as an actuary, and hopes to continue finding interesting ways of educating people about statistics. James is well-versed in R and Stata programming and enjoys teaching the intuition behind common statistical methods. James is a 2023 graduate of the University of Rochester with bachelor’s degrees in Statistics and Economics.

 


Issues in Coding Missing Values

October 11th, 2023 by

There’s no mincing words here. Missing values can cause problems for every statistician. That’s true for a lot of reasons, but it can start with simple issues of choices stage 1made when coding missing values in a data set. Here are a few examples.

Example 1: The Null License Plate

Researcher Joseph Tartaro thought it would be funny to get the following California vanity license plate: (more…)