Do-File Cheat Sheet: Who Wrote It What Assignment This Is Class and Section When It Was Written

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

Do-File Cheat Sheet

*** Initial Commands – Always use these commands when beginning a do-file ***
* Who wrote it *
* What assignment this is *
* Class and Section *
* When it was written *

clear
*Clears out the dataset that is currently in memory

capture log close


*Closes any log files you may have accidentally left open

cd “m:\your_directory\your_subdirectory”
*Changes the working directory to the specified drive and directory

log using filename,replace


*Opens log file called “filename,” replaces the contents with the current log

use filename
*Loads a data set called "filename" into Stata

*** Useful Commands Below ***

describe
*Lists each variable in Stata's memory

summarize
*Lists number of observations, mean, standard dev., min & max for a variable

tab
*Gives frequencies (counts), and is most useful with categorical variables

correlate var1 var2


*Computes the correlation between var1 and var2

generate newvar = something


*Generates a new variable called newvar which is whatever you specify

replace var1 = something if var2 == 1

*Replaces existing value of var1 with something if blah is equal to 1.


*”something” may be an expression. Replace can also be used without the "if"
*qualifier. Notice there is ALWAYS a distinction between "=" and "=="

drop var1
*Removes var1 from your dataset
*can be combined with an “if” statement

keep var1 var2


*keeps only the variables listed after the word “keep”
*can be combined with an “if” statement

regress y var1 var2, robust


*This computes the ordinary least squares estimates. y is the dependent *variable, all
others are independent variables. The robust command assumes *unequal variances

ttest varname1, by(varname2) unequal


*For two variables called "varname1" and "varname2," calculate a difference of means
test; assumes unequal variances

log close
*Closes and saves the current log file

You might also like