// Task 1: routine setup capture log close // close log file if one is open set more off // tells Stata not to pause or display the --more-- message estimates clear // drop all stored estimation results log using cda01b-ex1.log, replace text version 9.2 set scheme s2mono // scheme for graphs // pgm: cda01b-ex1.do // task: 1 - Introduction to Stata - Excercise // project: CDA Lab Guide // author: your name // date: today's date use nes2.dta, clear // Task 2: Keep abortion, age, didvote, fincome, partyid and preclin. // Explore these variables and drop missing cases. // Step 2.1 keep the 6 variables. // Step 2.2 explore your variables using -desc- -tab- and -dotplot- // Step 2.3 drop missing cases // Task 3: Generate partyaff based on partyid. // // If partyid is strong democrat or weak democrat, partyaff is 1. // If partyid is any type of independents, partyaff is 2. // If partyid is any type of Republican, partyaff is 3. // Recode other parties as missing; drop cases if partyaff is missing. // // Add labels to partyaff. Verify your steps. // Step 3.1 generate partyaff from partyid. // Step 3.2 recode partyaff and drop missing cases. // // partyaff=1 if partyid is 0 or 1 // partyaff=2 if partyid is 2 or 3 or 4 // partyaff=3 if partyid is 5 or 6 // partyaff=missing if partyid is 7 // Step 3.3 label variable and label values // Step 3.4 verify your results // Task 4: Generate vote from didvote. // // If didvote=1, then vote=1 // If didvote=5, then vote=0 // If didvote=6, then vote=. // // Add labels and verify your transformation. // Step 4.1 generate vote from didvote // Step 4.2 recode vote and drop the missing cases. // Step 4.3 add variable and value labels. // Step 4.4 verify // Task 5 Generate income from fincome. Then recode income in $1000s by // choosing the midpoint of each category of fincome. For the highest // category, >105k, multiply that number by 1.5. Make 66 (below 25K but NA) // and 77 (above 25K but NA) missing. Label and verify your transformation. // Step 5.1 create income from fincome // Step 5.2 recode income into $1000 using midpoints. // Step 5.3 label variable income // Step 5.4 verify // Task 6 [Optional]: First, create three dummy variables. // // democrat=1 if partyaff=1, else 0. // indep=1 if partyaff=2, else 0. // republican=1 if partyaff=3, else 0. // // Add labels. // Run an OLS regression of vote on age, income, indep & republican. // Run a logit of vote vote on age, income, indep & republican. // Compare results. // Step 6.1 create the dummy variables. Note that missing don't change. // Step 6.2 add labels and verify // Task 7 Run OLS and logit regressions and get coefficients using listcoef // Step 7.1 run OLS of vote on age, income, indep and republican. // Step 7.2 use listcoef to list coefficients // Step 7.3 run logit for same variables. // Step 7.4 use listcoef to list coefficients // Task 8: Save the new variables in a new data set. // Create a summary table of the variables and close the log file. // Step 8.1 save the data // Step 8.2 descriptive statistics // Step 8.3 close log file log close exit