1 / 47

Topics

Topics. Introduction to Stata Files / directories Stata syntax Useful commands / functions Logistic regression analysis with Stata Estimation GOF Coefficients Checking assumptions . Introduction to Stata. Note: we did this interactively for the larger part …. Stata file types. .ado

adrina
Download Presentation

Topics

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. Topics • Introduction to Stata • Files / directories • Stata syntax • Useful commands / functions • Logistic regression analysis with Stata • Estimation • GOF • Coefficients • Checking assumptions

  2. Introduction to Stata • Note: we did this interactively for the larger part …

  3. Stata file types • .ado • programs that add commands to Stata • .do • Batch files that execute a set of Stata commands • .dta • Data file in Stata’s format • .log • Output saved as plain text by thelog using command

  4. The working directory • The working directory is the default directory for any file operations such as using & saving data, or logging output • cd “d:\my work\”

  5. Saving output to log files • Syntax for the log command • log using filename [, append replace [smcl|text]] • To close a log file • log close

  6. Using and saving datasets • Load a Stata dataset • use d:\myproject\data.dta, clear • Save • save d:\myproject\data, replace • Using change directory • cd d:\myproject • Use data, clear • save data, replace

  7. Entering data • Data in other formats • You can use SPSS to convert data • You can use the infile and insheet commands to import data in ASCII format • Entering data by hand • Type edit or just click on the data-editor button

  8. Do-files • You can create a text file that contains a series of commands • Use the do-editor to work with do-files • Example I

  9. Adding comments • // or * denote comments stata should ignore • Stata ignores whatever follows after /// and treats the next line as a continuation • Example II

  10. A recommended structure capture log close //if a log file is open, close it, otherwise disregard set more off //dont'pause when output scrolls off the page cd d:\myproject //change directory to your working directory log using myfile, replace text //log results to file myfile.log … here you put the rest of your Stata commands … log close //close the log file

  11. Serious data analysis • Ensure replicability use do+log files • Document your do-files • What is obvious today, is baffling in six months • Keep a research log • Diary that includes a description of every program you run • Develop a system for naming files

  12. Serious data analysis • New variables should be given new names • Use labels and notes • Double check every new variable • ARCHIVE

  13. Stata syntax examples

  14. The Stata syntax • Regress y x1 x2 if x3 <20, cluster(x4) • Regress = Command • Whataction do you want to performed • y x1 x2 = Names of variables, files orotherobjects • Onwhatthings is the commandperformed • if x3 <20 = Qualifieronobservations • Onwhichobservationsshould the commandbeperformed • , cluster(x4) = Options • What special thingsshouldbedone in executing the command

  15. Examples • tabulate smoking race if agemother > 30, row • Example of the if qualifier • sum agemother if smoking == 1 & weightmother < 100

  16. Elements used for logical statements

  17. Missing values • AutomaticallyexcludedwhenStata fits models; they are stored as the largestpositivevalues • Beware!! • The expression ‘age > 65’ canthusalsoinclude missing values • Tobesure type: ‘age > 65 & age != .’

  18. Selecting observations • drop variable list • keepvariable list • drop ifage < 65

  19. Creating new variables • generate command • generate age2 = age * age • generate • see help function • !!sometimes the command egen is a useful alternative, f.i. • egen meanage = mean(age)

  20. Useful functions

  21. Replace command • replace has the same syntax as generate but is used to change values of a variable that already exists • gen age_dum = . • replace age = 0 if age < 5 • replace age = 1 if age >=5

  22. Recode • Change values of exisiting variables • Change 1 to 2 and 3 to 4: recode origvar (1=2)(3=4), gen(myvar1) • Change missings to 1: recode origvar (.=1), gen(origvar)

  23. Logistic Logistic regression

  24. Logistic regression • Lets use a set of data collected by the state of California from 1200 high schools measuring academic achievement. • Our dependent variable is called hiqual. • Our predictor variable will be a continuous variable called avg_ed, which is a continuous measure of the average education (ranging from 1 to 5) of the parents of the students in the participating high schools.

  25. OLS in Stata

  26. Logistic regression in Stata

  27. Multiple predictors

  28. MODEL FIT Consider model fit using: The likelihood ratio test The pseudo-R2 (proportional change in log-likelihood) The classification table

  29. Model fit: the likelihood ratio test

  30. Model fit: LR test

  31. Pseudo R2: proportionalchange in LL

  32. Classification Table

  33. Classification Table

  34. Interpreting coefficients

  35. Interpreting coefficients: significance

  36. Interpretation of coefficients: direction

  37. Interpretation of coefficients: direction

  38. Interpretation of coefficients: Magnitude

  39. Interpretation of coefficients: Magnitude

  40. Ok now

  41. Multicollinearity

  42. Influential observations

  43. To do • Perform a logisticregression analysis • Use apilog.dta • Awards = dependentvariable

More Related