Data Basics (Data Analysis)
To get a sense of how to work with data and the types of data that Stata handles, we will look at a data set on life expectancy in 68 countries:
If the file lifeexp.dta is not already in your course folder then download it into your course folder.
Get familiar with the data by importing it using use then complete the following tasks. One thing to remember is that in Stata creating a variable requires one equal sign (=) while using logic expressions, like [if exp] requires two equal signs (==).
- Describe the data (using
describe). Which variable has a value label? - Calculate the mean life expectancy (using
sumfor summarize). What is the mean and standard deviation of life expectancy? - Calculate the median life expectancy (using the
detailoption tosum). What is median life expectancy? - Sort the data by country (using
sort). Alphabetically, what is the first and last country in the data set? - List the regions in the data set (using
tabfor tabulate). How many regions are there? - Stata can label data (recall the region label). This means when you look at the data you see the label, but the label actually applies to a number. List the regions by their number (using the
nolaboption totab). What number is assigned the label South America? - Calculate the mean life expectancy by region (using the prefix
bysfor bysort to thesumcommand). What is mean life expectancy in Europe and Central Asia? - Filter the data to calculate median population growth for North America (using the
if [exp]conditional onsum). What is median population growth in the region? - Remove rows with null values of safewater (using
drop if). How many observations were dropped? - Create a new data file called
lifeexp_no-swfor no safewater (usingsave). What is the size in KB of this new file (look under data in the Properties Window)?