0% found this document useful (0 votes)
28 views1 page

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

This document provides a cheat sheet of useful commands for Stata do-files. It begins with initial commands to include identifying information and set up the working directory and log file. Descriptive commands like describe, summarize, tab, and correlate are listed, as well as commands for generating, replacing, dropping, and keeping variables. Examples of regression and t-test commands are also provided. The document concludes with closing the log file.

Uploaded by

clarisayerovi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views1 page

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

This document provides a cheat sheet of useful commands for Stata do-files. It begins with initial commands to include identifying information and set up the working directory and log file. Descriptive commands like describe, summarize, tab, and correlate are listed, as well as commands for generating, replacing, dropping, and keeping variables. Examples of regression and t-test commands are also provided. The document concludes with closing the log file.

Uploaded by

clarisayerovi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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