1 / 23

Stata and logit recap

Stata and logit recap. Topics. Introduction to Stata Files / directories Stata syntax Useful commands / functions Logistic regression analysis with Stata Estimation Goodness Of Fit Coefficients Checking assumptions. Overview of Stata commands.

fallon
Download Presentation

Stata and logit recap

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 and logit recap

  2. Topics • IntroductiontoStata • Files / directories • Stata syntax • Usefulcommands / functions • Logisticregression analysis withStata • Estimation • Goodness Of Fit • Coefficients • Checkingassumptions

  3. Overview of Stata commands • Note: we did this interactively for the larger part …

  4. Stata file types • .ado • programs thataddcommandstoStata • .do • Batch files thatexecute a set of Statacommands • .dta • Data file in Stata’s format • .log • Output saved as plaintextby thelog usingcommand(youcouldadd .txt as well)

  5. The working directory • The working directory is the default directory forany file operations such as using & saving data, or logging output cd “d:\mywork\”

  6. Saving output to log files • Syntax for the log command log using[filename], replacetext • Toclose a log file log close

  7. 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 usedata, clear save data, replace

  8. Entering data • Data in other formats • Youcanuse SPSS toconvertdata thatcanbereadwithStata. Unfortunately, not the other way around (anymore) • Youcanuse the infileandinsheetcommandsto import data in ASCII format • Direct import and export of Excel files in Stata is possibletoo • Entering data byhand (don’t do this…) • Type editor just click on the data-editor button

  9. Do-files • Youcancreate a text file thatcontains a series of commands. It is the equivalent of SPSS syntax (but way easiertomemorize) • Usethe do-file editor toworkwith do-files

  10. Addingcomments in do-files • // or * denotecommentsstatashouldignore • Stataignoreswhateverfollowsafter /// andtreats the next line as a continuation • ExampleII

  11. A recommendedtemplate for do-files 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

  12. 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

  13. Serious data analysis • New variables shouldbegiven new names • Usevariablelabelsandnotes (I don’tlikevaluelabelsthough) • Double check every new variable • ARCHIVE

  14. Stata syntax examples

  15. Stata syntax example 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 appearbehind the comma • What special thingsshouldbedone in executing the command

  16. More examples tabulate smoking race if agemother>30, row More elaborateif-statements: sumagemother if smoking==1 & weightmother<100

  17. Elements used for logical statements

  18. Missing values • AutomaticallyexcludedwhenStata fits models (same as in SPSS); they are stored as the largestpositivevalues • Beware!! • The expression“age>65” canthusalsoinclude missing values (these are alsolargerthan 65) • Tobesure type: “age>65 & age!=.”

  19. Selecting observations drop [variable list] keep[variable list] drop ifage<65 Note: they are thengoneforever. This is notSPSS’s [filter] command.

  20. Creating new variables Generating new variables generateage2 = age*age (for more complicatedfunctions, therealsoexists a command “egen”, as we willsee later)

  21. Useful functions

  22. Replace command • replace has the same syntax as generate but is usedto change values of a variablethatalreadyexists gen age_dum5 = . replace age_dum5 = 0 ifage < 5 replace age_dum5 = 1 ifage >=5

  23. Recode • Change values of existing variables • Change 1 to 2 and 3 to4 in origvar, and call the new variable myvar1: recodeorigvar (1=2)(3=4), gen(myvar1) • Change 1’s tomissings in origvar, and call the new variable myvar2: recodeorigvar(1=.), gen(myvar2)

More Related