stata_trainingmanual

  • View
    409

  • Download
    0

Embed Size (px)

Text of stata_trainingmanual

Using Stata for Survey Data Analysis

Nicholas Minot International Food Policy Research Institute Washington, DC, USA

30 November 2009

Minot

Using Stata for Survey Data Analysis

Table of Contents

SECTION 1: INTRODUCTION TO TRAINING GUIDE ............................................................... 1 Background ......................................................................................................................................... 1 Objectives ........................................................................................................................................... 1 Course requirements ........................................................................................................................... 1 Organization of the course .................................................................................................................. 1 SECTION 2: REVIEW OF SURVEY DATA CONCEPTS ............................................................ 3 List of useful terms ............................................................................................................................. 3 Structure of BLSS data files ............................................................................................................... 4 SECTION 3: INTRODUCTION TO STATA .................................................................................. 5 Menu bar ............................................................................................................................................. 5 Tool bar ............................................................................................................................................... 6 Stata windows ..................................................................................................................................... 6 SECTION 4: EXPLORING DATA FILES ...................................................................................... 9 cd ......................................................................................................................................................... 9 clear ..................................................................................................................................................... 9 use ....................................................................................................................................................... 9 describe ............................................................................................................................................. 10 list...................................................................................................................................................... 10 summarize ......................................................................................................................................... 11 tabulate, tab1, tab2 ............................................................................................................................ 12 bysort prefix ...................................................................................................................................... 14 save ................................................................................................................................................... 14 in ....................................................................................................................................................... 15 help.................................................................................................................................................... 15 set ...................................................................................................................................................... 15 Exercises for exploring the BLSS ..................................................................................................... 15 SECTION 5: STORING COMMANDS AND OUTPUT .............................................................. 17 Using the Do-file Editor.................................................................................................................... 17 Saving the output .............................................................................................................................. 18 Using Stata output ............................................................................................................................. 20 Exercises for saving commands and output ...................................................................................... 21 SECTION 6: CREATING NEW VARIABLES AND ADDING LABELS ................................. 22 generate ............................................................................................................................................. 22 replace ............................................................................................................................................... 22 tabulate generate .......................................................................................................................... 23 Using functions ................................................................................................................................. 26 recode ................................................................................................................................................ 26 xtile ................................................................................................................................................... 27 label variable ..................................................................................................................................... 28 label define ........................................................................................................................................ 28 label values........................................................................................................................................ 29 #delimit ............................................................................................................................................. 30 Exercises for creating variables and labels ....................................................................................... 31

Using Stata for Survey Data Analysis

Minot

SECTION 7: MAKING TABLES TO DESCRIBE DATA ........................................................... 32 tabulate summarize ...................................................................................................................... 32 tabstat ................................................................................................................................................ 33 table ................................................................................................................................................... 34 Using weights.................................................................................................................................... 36 SECTION 8: MODIFYING DATA FILES .................................................................................... 38 rename ............................................................................................................................................... 38 drop ................................................................................................................................................... 38 keep ................................................................................................................................................... 38 sort .................................................................................................................................................... 38 compress ........................................................................................................................................... 38 collapse ............................................................................................................................................. 39 merge ................................................................................................................................................ 40 append ............................................................................................................................................... 41 fillin ................................................................................................................................................... 42 reshape .............................................................................................................................................. 44 SECTION 9: PRESENTING DATA WITH GRAPHS ................................................................. 45 graph ................................................................................................................................................. 45 scatter ................................................................................................................................................ 46 graph options..................................................................................................................................... 46 SECTION 10: REGRESSION ANALYSIS .................................................................................... 49 regress ............................................................................................................................................... 49 probit ................................................................................................................................................. 50 predict ..........................................................................