StataIntro - Stata Files There are four main types of Stata files.do files.log files.dta files.gph files-> txt files with your commands saved for future

StataIntro - Stata Files There are four main types of Stata...

This preview shows page 1 - 4 out of 16 pages.

Stata Files There are four main types of Stata files: .do files -> txt files with your commands saved, for future reference and editing .log files -> txt files with the output from your .do files, for future reference and printing .dta files -> data files in Stata format .gph files -> graph files in Stata format Other types of Stata files: .ado files -> programs in Stata (every command you use has an associated .ado file on your computer) .smcl files -> default format for log files unless you tell Stata to use .log extension The Basics While you can use Stata interactively, most work is done in .do files to aid in (i) editing mistakes and (ii) saving your work for future reference. Typical structure of a .do file: capture log close clear set more off set mem 20m log using filename .log, replace . . . log close -> everything between the log using line and the log close line will be saved in the .log file -> -capture- in front of a command line tells Stata to ignore the line if there is an error associated with it -> -replace- in the log using line tells Stata to overwrite the log file if it exists… be sure this is what you want -> -set mem XXXm- allocates memory to Stata. If you get an error message “insufficient memory,” then more memory needs to be allocated until your program works, or your computer breaks -> lines that begin with an “*” are ignored by Stata; these are useful for making comments to yourself -> by default, Stata assumes that each line in the .do file is a separate command; alternatively, you can tell Stata to interpret a “;” as the end of each command line… this is done by typing: #delimit ; **turns on the ; option . . . #delimit cr **turns the ; option off .do files can be written using the do file editor within Stata, or using any other text editor of your liking
Image of page 1

Subscribe to view the full document.

.do files can be executed within Stata by typing in the command window: do filename or, by opening the do file in the do file editor and clicking the “do current file” button or, by clicking on “Do…” in the “File” menu within Stata and clicking on the .do file -> .log files can be opened by clicking on the file in your directory (will use notepad by default) or in any text editor Help Files Stata has a built-in help window, which is a stripped-down version of the manual. Relevant commands: help commandname -> commandname must be the correct name of a Stata command search keyword -> executes a keyword search for relevant commands in official Stata findit keyword -> executes a keyword search for relevant commands in official Stata and in unofficial Stata online; if you find a command, you can then follow the relevant clicks to download it; it will placed automatically in a directory that Stata searches and it will act just like any “official” Stata command once installed. USER BEWARE!
Image of page 2
Data Basics Here is an example .do file to open a Stata data set in Stata, and do some basic manipulations capture log close clear set more off set mem 20m log using filename .log, replace use datafilename , clear *list the data for viewing list *list certain variables list varlist
Image of page 3

Subscribe to view the full document.

Image of page 4

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask 0 bonus questions You can ask 0 questions (0 expire soon) You can ask 0 questions (will expire )
Answers in as fast as 15 minutes