Week 1 PC Lab

The main software we will be using will be:

Today, we will take a brief look at Stata.

  1. Log on, and start Stata: Hit the Windows key, click S -> Specialist Software -> Stata or type "Stata" in the search box.
  2. The Stata window has four panels: the big one is for output, and the wide one at the bottom is for entering commands
  3. Load a data set: Type sysuse nlsw88 in the command panel and press return. This command loads an example file that comes with Stata (it's an extract from the 1988 US National Longitudinal Study of Women).
  4. The bottom left window shows you what variables are in the dataset
  5. You can get more information about the variables by entering the command describe or des for short
  6. You can look at the variables by entering the command list or by clicking on one of the data-editor icons in the toolbar
  7. What does the data look like? You can summarise variables by entering the command summarize varname, for example su age
  8. If the variable has a small number of distinct elements, you can tabulate it: e.g., tab occupation
  9. Do this with a number of variables to get a feel for the data
  10. We can also make two-way tables: for example, tab occ never_married
  11. Graphs are easy: try histogram age or graph pie, over(occupation). Explore the graphics menu too.

Univariate analysis PC Lab

Univariate analysis involves looking at one variable at a time. It's less interesting than bivariate, but it is an important building block. It gives us numerical and graphical summaries of single variables.

Numerical summaries

We need to distinguish between types of variables when we are summarising them. A key distinction is whether a variable has categories (e.g., religion) or whether the numbers have implicit meaning (e.g., count variables like how many children are in a family, or measures like time spent watching screens). If a variable has categories (or small numbers of values), we can summarise it completely with a frequency table:

  . sysuse nlsw88
  . tab industry

Note this gives you the number in each category, the percentage and the cumulative percentage (the last makes sense only when the variable is ordered).

When a variable consists of numbers that are meaningful, summaries like the mean and spread are useful.

  . summarize wage

This gives the number of cases, mean, standard deviation, and highest and lowest values for the variable. These give a good deal of info about the variable. What happens if we try to tabulate this variable:

  . tab wage

You get pages and pages of output because it has so many values. Press the Q key to escape. However, not all variable which are meaningful numbers are not suited to tabulation. Age for instance does not have many values in this data set:

  . tab age

We can get the median of a numerically-meaningful variable too:

  . centile age

Note that in the tab age output, the cumulative percentage goes above 50% for 39, which centile determines is the median value.

Get the median for wage too, and compare it with the mean for wage:

  . centile wage

Graphical summaries

The same division of variables matters for graphical summaries. There they are categorical (or have relatively few distinct values), we can use bar charts (where the height of the bar is proportional to the number in the category) or pie charts (where the angle of each wedge give the same info).

    . gen n = 1
    . graph bar (count) n, over(industry)
    . graph hbar (count) n, over(industry)
    . graph pie, over(industry)
  

Where the number is meaningful (like wage) we can make histograms and box plots

    . histogram wage
    . graph box wage
  

Brendan Halpin
Department of Sociology
University of Limerick
brendan.halpin@ul.ie