Introduction
Stata can hold vast amounts of data. Sometimes, instead of scrolling through the edit window, you want to be able to call up just the data that are relevant to you. Here, we’ll show you variations of the list command in Stata that can help you.
Create Data
First, we’ll create mock data, then we’ll show you how to apply the list command. Let’s assume we’re measuring IQ for 1,000 subjects.
set obs 1000
gen subj = _n
label variable subj "Subject"
gen iq_a = runiform(90,140)
gen iq = round(iq_a)
drop iq_a
label variable iq "IQ"
Bear in mind that, when we list, we are simply displaying some subset of data from the main dataset in Stata’s main command window. We are not changing or manipulating data.
Basic Listing
Let’s saw you’re interested in looking at the last 30 rows. You could type:
list in 971/1000
Here’s what you get:
What if you are interested in only a single IQ value, that of subject 26? You could type:
list in 26
Notice that the list command, issued without modifications, brings up all variables. You can list any number of variables you like. For example, if you just wanted to see the IQ value for subject 26 without also seeing the subject number, you could try:
list iq in 26
Conditional Listing
Let’s say you want to list each of the first 30 subjects with an IQ greater than 120. Try the following code:
list in 1/30 if iq > 120
Or you could go further and list everyone in the dataset who has an IQ greater than 139:
list in 1/1000 if iq > 139
What if you only want to list people with an IQ greater than 139 who are among the first 500 subjects, sequentially numbered? Try:
list in 1/1000 if iq > 139 & subj < 501
As you can see, list can be combined with conditional statements in powerful ways in Stata.
BridgeText can help you with all of your statistical analysis needs.