1 / 16

Stata Review Session

Stata Review Session. Economics 1018 Abby Williamson and Hongyi Li November 17, 2006. Agenda. Administrative Issues Empirical exercise - clarifications Log and .do files in Stata Introducing Variables Reviewing Stata Commands An Example Questions. Administrative Issues.

Download Presentation

Stata Review Session

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Stata Review Session Economics 1018 Abby Williamson and Hongyi Li November 17, 2006

  2. Agenda • Administrative Issues • Empirical exercise - clarifications • Log and .do files in Stata • Introducing Variables • Reviewing Stata Commands • An Example • Questions

  3. Administrative Issues • Office Hours • Abby – Monday, November 27, 10-12 Tuesday, November 28, 4-6 • Hongyi – Wednesday, November 29, 6-8 • Problem Set Questions • E-mail BOTH TFs with questions. We will reply to the entire class. Keep track of these e-mails as common questions will arise. • Addresses: Abby.Williamson@gmail.com, hongyi@gmail.com

  4. Empirical Exercise – some clarifications • Question 2b: you may organize your graphs in whichever way you see fit. • For example: with happiness, generate 1 bar graph for each wave, with 1 bar per country representing average level of happiness • Question 3: Don’t have to include too many controls (which would reduce significance). • Also, don’t use educational levels (which are unevenly measured across countries) • Question 4: Don’t just use US data. You have to show that trust has declined, relative to other countries, in younger cohorts in the US.

  5. Keeping Track of Stata Work • Opening data • Open Stata, use “open” button on menu (folder) to open relevant dataset • Dataset too big? Set memory higher: • set mem 500m (or bigger …) • Open a log • Ex: log using c:/WilliamsonPS • Remember to use: capture log close • Start a .do file • Use the envelope button to open a .do file, save it under a name you’ll remember. Write and run your program from there so that you can re-run analyses without rewriting everything.

  6. Example: A Few Variables • E037.- Government responsibility • People should take more responsibility to provide for themselves vs. The government should take more responsibility to ensure that everyone is provided for • 1 'People should take more responsibility' • 2 '2' • 3 '3' • 4 '4' • 5 '5' • 6 '6' • 7 '7' • 8 '8' • 9 '9' • 10 'The government should take more responsibility'

  7. Example: A Few Variables • A025.- Respect and love for parents With which of these two statements do you tend to agree? (CODE ONE ANSWER ONLY) • A. Regardless of the qualities and faults of one's parents, one must always love and respect them. • B. One does not have the duty to respect and love parents who have not earned it by their behavior and attitudes. • 1 'Always' • 2 'Earned' • 3 'Neither'

  8. Reviewing Stata Commands • Rename • Ex. rename e037 big_govt (Renames variable e037 “big_govt”) • Ex. Rename a025 obedience(Renames variable a025 “obedience”) • Recode • Ex. recode obedience (1=1) (0=2) (Recodes the variable so that always=1, earned=0)

  9. Reviewing Stata Commands • Tabulate • Ex. tab obedience(Tells what proportion of respondents falls into each category.) • Ex. tab obedience if sex==1(Tabulates obedience for female respondents.) • Summarize • Ex. sum big_govt (Gives basic summary statistics (mean, range, etc.) for big_govt.)

  10. Reviewing Stata Commands • Sort and By • Ex. sort country by country: tab obedience (Sorts by country and then tabulates obedience for each country.) • Collapse • Ex. collapse (mean) age height, by (country) (Makes a new dataset with one observation per country, and two variables: the mean age and mean height for the people of that country)

  11. Reviewing Stata Commands • Graph • Ex. graph twoway scatter age height • (Generates a scatter plot with age and height as the axes) • Ex. graph bar (mean) age, over (country) • (Generates a bar graph where each bar corresponds to a country and the height of each bar is the average age for that country)

  12. Reviewing Stata Commands • Generate • Ex. gen highhealth=0 replace highhealth=1 if health==1 (Generates a dummy in which all observations equal 0 unless respondent reports excellent health, in which case highhealth is replaced with 1.) • Ex. gen agesq=age*age(Creates a variable that is the square of the respondent’s age.) • Ex. gen femeduc=sex*educ(Creates an interaction variable that measures the differential impact of education on women.)

  13. Reviewing Stata Commands • Drop • Ex. drop a001 a002 a003 a004(Drops those four variables, keeping all others.) • Ex. drop if age<18(Drops all children.) • Keep • Ex. keep a001 a002 a003 a004(Keeps those four variables, dropping all others.) • Ex. keep if age<18(Keeps only children.)

  14. Reviewing Stata Commands • Correlate • Ex. corr big_govt obedience (Gives the correlation between health and happiness.) • Regress • Ex. reg big_govt obedience educ age income, r (Regresses happiness on health controlling for education, age, and income. “,r” indicates use of robust standard errors – almost always a good idea.)

  15. Reviewing Stata Commands • Regress • Ex. reg big_govt obedience educ age income, r • (Regresses happiness on health controlling for education, age, and income. “,r” indicates use of robust standard errors – almost always a good idea.) • Ex. xi: reg big_govt obedience educ i.country, r • (Regresses happiness on health controlling for education, age, and income, with country fixed effects.)

  16. Reviewing Stata Commands • IV Regress • Ex: ivreg2 big_govt (obedience=religion) educ age income, r • (Regresses happiness on health controlling for education, age, and income, while instrumenting for happiness using religion.) • ivreg2 is preferred to ivreg, although both run 2SLS. You have to install it – search for it from the help window.

More Related