170 likes | 291 Views
MPP Stats Bootcamp W (12:00-1:50), Week 9. SOC 516 Class Tutor: Daniel Hauser ( hauserd@onid.orst.edu ) ECON 524 GTA (and SOC 516 substitute tutor): Joey Carroll Instructor : Dr . Alison Johnston ( Alison.Johnston@oregonstate.edu ) http://oregonstate.edu/cla/polisci/alison-johnston.
E N D
MPP Stats BootcampW (12:00-1:50), Week 9 SOC 516 Class Tutor: Daniel Hauser (hauserd@onid.orst.edu) ECON 524 GTA (and SOC 516 substitute tutor): Joey Carroll Instructor: Dr. Alison Johnston (Alison.Johnston@oregonstate.edu) http://oregonstate.edu/cla/polisci/alison-johnston
Bootcamp Outline • Questions from previous three weeks? • Especially last week? • Data Management Commands • Stata Practice • Testimonial • Bootcamp concluding comments
Pre-Lecture • Open the dataset • 2nd to last sheet in the Bootcamp’s Excel Workbook • Copy into Stata, type describe • Minimize Stata and follow along with Powerpoint
Why Learn Data Management in Stata? • Efficiency • Accuracy • Consistency
Random Useful Commands • help X • Opens a box with help on a specific command, “X” • findit X • Searches for a command “X” in a new window • ssc install X • Installs a new command, “X”. If you don’t know the exact command name, findit!
Data Management Commands • set memory 100m, permanently • If you use Stata 12… • describe • General description of dataset and format of variables • ‘describe x’ displays same information but only about variable x • clear • Removes all data currently loaded
Loading Stata data into Stata • use (only if data is in Stata format: dataset.dta) • If data is in home directory: • use dataset • If not in home directory, need full file name: • use “z:/hauserd/soc/dataset.dta” • Hosted on a website: • use http://www.oregonstate.edu/data/dataset.dta
Loading SPSS or SAS data into Stata • Stat/Transfer: Great program (costs money) • Re-Save in SPSS and SAS • SPSS: Can save as Stata data file (.dta) • SAS: Can save as .csv then copy+pastein Excel • Downloadable Commands (ssc install …) • usesas: usesas using “myfile.sas7dbat” • Need SAS installed • usespss: usespss using “myfile.sav” • Can only be used in 32bit version of Stata…open Stata 10/SE in Umbrella to utilize • Do NOT need SPSS installed
Data Management Commands • destringvar1 • Convert data from string to numeric variable. • Remove missing data in a variable: • destring var1, replace ignore(NR) • sort var1 • Arranges the observations alphabetically or numerically based upon the variable indicated. • order var1 var2 • Brings the variables to the top of the variable list, in the order listed.
Data Management Commands • drop var1 • Eliminate a variable or an observation. • Drop observations in a range: • drop in 500/800 • Can also use if: • drop in 500/800 if > 0 • keep var1 • Opposite of drop, only the variables indicated are retained, the rest are removed. Same rules as drop. • rename var1 party • Changes the name of a variable.
Data Management Commands • label var1 ... • Multi-faceted tool, but we will only go into one use today, the labeling of groups of observations in a variable. • encode var1, gen(var2) • Creates a new numeric variable (var2) out of a string variable (var1). • replace var1=. if var1==4 • Allows for modification of numerical observations within a variable.
Data Management Commands • generate var1 • Commonly used command that creates a new variable. • Normally incorporating other operators or functions: • gen var1=fargo if var1>3 • egen • Super-generate.
StataConditional Operators • After the if statement…and other uses!
Stata Lab Exercises • How to remove string data from an otherwise numeric variable • How to arrange your variables and observations • How to keep and drop specific portions of the data • How to create a new numeric variable out of a string variable • How to replace numeric values with other numeric values within a variable • How to replicate data with a different codification • How to rename a variable in Stata.
Ending Comments • Do practice problems over break!!! • Use all of your resources • Your cohort • help command • Online resources • SOC 516 Social Research Methods Tutor: • Daniel Hauser (me) • ECON 524 Econometrics GTA: • Joey Carroll (her)