Home | GLMs | Multilevel | Survival | Demography | Stata | R
Home Lecture Notes Stata Logs Datasets Problem Sets

Linear Models in Stata

We start with the linear models in Chapter 2 of the lecture notes, showing how to use the regress command in Stata to fit regression, analysis of variance, and analysis of covariance models.

2.1 The Program Effort Data

For a brief description of the program effort data see the lecture notes or point your browser to the datasets page. All datasets used in the course are now available as Stata files and can be read directly from the web:

. use http://data.princeton.edu/wws509/datasets/effort
(Family Planning Effort Data)

(The datasets remain available as plain text files that can be read using almost any software. Please refer to the datasets page for more information. The steps I followed to create this particular dataset are documented in my Stata Tutorial.)

Let us list the data to check we got them OK:

. list country setting effort change, clean
 
              country   setting   effort   change  
  1.          Bolivia        46        0        1  
  2.           Brazil        74        0       10  
  3.            Chile        89       16       29  
  4.         Colombia        77       16       25  
  5.        CostaRica        84       21       29  
  6.             Cuba        89       15       40  
  7.     DominicanRep        68       14       21  
  8.          Ecuador        70        6        0  
  9.       ElSalvador        60       13       13  
 10.        Guatemala        55        9        4  
 11.            Haiti        35        3        0  
 12.         Honduras        51        7        7  
 13.          Jamaica        87       23       21  
 14.           Mexico        83        4        9  
 15.        Nicaragua        68        0        7  
 16.           Panama        84       19       22  
 17.         Paraguay        74        3        6  
 18.             Peru        73        0        2  
 19.   TrinidadTobago        84       15       29  
 20.        Venezuela        91        7       11  

The next thing we want to do is plot the data for a closer look. The importance of becoming familiar with your data before undertaking sophisticated analyses cannot be over-emphasized. The following command creates scatterplots of all pairs of variables, reproducing Figure 2.1 in the notes.

. graph matrix change setting effort, ///
>   title("Figure 2.1: Scatterplot Matrix")
 
. graph export fig21.png, width(400) replace
(file fig21.png written in PNG format)

After generating the graph you can print it using the command graph print, save it in stata's own format using graph save, or export it into other formats using grap export. I exported the graph to portable network graphics (PNG) format for inclusion on this web page.

If you want to import the graph into a word processing program such as Word you are better off exporting to windows metafile format (WMF) or the enhanced variant (EMF). The advantage of the metafile formats is that they are vector graphics that can be resized after inclusion in the document.

Windows interactive users can also print the graph by choosing File|Print Graph on Stata's menu, or save it in a variety of formats by choosing File|Save Graph. Alternatively, you can choose Edit|Copy to copy the graph to the clipboard and then Edit|Paste to insert it into your favorite word processor.

Also, your graph may look slightly different than mine, depending on the scheme you use. The Stata default is called s2color, but I tweaked it a bit to use a white background and match the color of the headings on this page. Type help scheme if you are interested in this subject.


Continue with 2.4 Simple Regression