Skip to main content

Search this Site

DartPulse Alerts

Chrome Printing Issues

 

DartPulse Outages

Overall System Status:

Upcoming Scheduled Outages

New to Dartmouth?

Resources for:

Information Security

Connect with Computing

facebook twitter Wordpress Blog

Introduction to Stata

Installing Stata

Stata is campus-licensed statistical software. The two supported versions at Dartmouth are Intercooled (IC) Stata 12 and 13 for Windows and Mac OS X machines.

You can download the software from the software download site. Follow the link for your computer, and then choose "Windows" or "Macintosh" then "Academic Software." You'll find Stata in the list.

In order to run the software you need a supporting application called KeyAccess. See Using KeyAccess to Activate Software (Mac instructions) (Windows instructions) for help with this.

KeyAccess (K2Client) allows you to run KeyServed applications. KeyServed applications are controlled by a network server which limits the number of simultaneous users to match our license agreement with the vendor. The Dartmouth KeyServer address is keyserver.dartmouth.edu. This must be set in the KeyAccess setup dialog.  Computers must be on the Dartmouth network, or using the Dartmouth VPN, to use KeyServed software.

Stata will download as a Zip file for Windows computers and as a DMG file on Macintosh computers.

For Windows users, open Zip folder (Stata13) and then Stata13 Installer and double click the Stata13MSI file. When the installation is complete, launch the program by clicking Start then All Programs then Stata13 then StataIC 13 (64-bit) or StataIC13 (32-bit) (If you are using 64-bit OS, you will see the former otherwise the latter) .  Pull the STATA.LIC file in the download zip folder into Program Files (x86)/Stata13 if you were prompted to ask some license information.

For Stata12, substitute 12 for 13 in the above instructions

For Macintosh users, when the download is complete,  click the file that was downloaded to mount it (this may happen automatically). To install the program:

v12: click the appropriate Install-Stata icon (most users will want the Intel version; old Macs may need the PPC version. This will save any existing Stata as Stata-old, then copy the new Stata to the Applications folder.

v13: Drag the Stata folder to Applications. v13 only works on Macs with OSX 10.6 and newer.

To uninstall the program, just delete the entire Stata folder from Applications.

When installing Stata, do not enable automatic updates, that can break the KeyServed version of Stata.  You do not need to register the product.

If you have trouble please stop by the Student IT Service Desk for help. We are located in 178J Berry Library.

Top of Page

Support

For questions about using Stata not answered on this page, or for consulting requests regarding statistics, contact Jianjun Hua at 646-6552 or statistical.consulting@dartmouth.edu.

Stata Windows

When you launch Stata, you'll see several windows that you'll use while working with the program:

  • Command - provides an input area for entering Stata command statements.
  • Results - shows you the commands you've entered along with their results. (If "more" appears at the bottom, press ‘enter' to continue scrolling the results or ‘q' to quit.)
  • Review - displays a history of the most recent commands entered. Highlighting a command here will make it appear in the Command window.
  • Variables - lists the variables contained in the current data set. Only one data set at a time can be current in Stata. Highlighting a variable in this window will make it appear in the Command window.
  • Data Editor - displays the current data set in spreadsheet format. The data editor can also be used when cutting and pasting data to and from other spreadsheet applications like Excel. 
  • Graph - displays the results of graphics associated command statements.

Top of Page

Stata Log Files

Log files keep a record of the command statements you enter and Stata's output. Specifying a filename saves the log to a file; saving as a log format rather than the default SMCL format will allow you to open the log in other applications (like Word and Notepad).

A log file can be opened/started from the File - Log menu or with the log command. The replace option overwrites the log file; append adds to it. On or off option turns the logging on or off in the middle of a session; close option closes the log file.

log using "c:\my documents\clients\hsb.log", replace text
log off (you practice for a while, not wanting to save all your mistakes)
log on (you turn the log back on so you can save real work)

It's wise to open a log file at the beginning of a session, turning it on or off as you need to save commands and results.

Top of Page

Stata Data Files

Stata can read the following filetypes:

.dta - a data file in Stata format
.txt - data in ASCII (text) format
.raw - data in ASCII (text) format
.xls - a data file in Excel format

Different command statements are used to load data sets in different file formats. Most commonly you'll issue the use command to read Stata formatted data sets.

  • File - Open menu - opens a data file already in Stata format
  • use - opens a data file that is already in Stata format. The directory path must be specified.
    use "c:\my documents\clients\hsb.dta"
  • use13 - opens a data file, which was created and saved in Stata 13, in Stata 12

         ssc install use13

         use13 "mystatadataset.dta"

  • insheet - reads (only) comma or tab-delimited data; single line per observation.

    insheet id sex race ses sctyp hsp locus concept mot car rdg wrtg math sci civ using ":Macintosh HD:Desktop Folder:hsb2.raw"
  • infile - reads free field data and tab- or comma-delimited data; can have multiple records

    infile id sex race ses sctyp hsp locus concept mot car rdg wrtg math sci civ using ":Macintosh HD:Desktop Folder:hsb1.raw"
  • infix - reads fixed field data

    infix id 1-3 sex 4-8 race 9-13 ses 14-18 sctyp 19-23 hsp 24-28 locus 29-33 concept 34-38 mot 39-43 car 44-48 rdg 49-53 wrtg 54-58 math 59-63 sci 64-68 civ 69-73 using ":bananas:Users:ac:Desktop:hsb.txt"

You can often cut and paste data from other applications into Stata's data editor.

Data sets in Stata follow the format where rows are cases/observations and columns are variables.

Top of Page

General Commands

  • clear - clears data out of memory.
  • search - searches Stata help for matching strings. This allows you to find help on command statements and return codes which appear alongside of error messages. If you make a mistake with a Stata command, it may return an error message along with a return code {for example, r(199)}. The search command can be used to get a more detailed description of the return code.

    search r(199)
  • generate - computes a new variable based on an expression.

Top of Page

Basic Analysis Commands

  • tabulate - gets counts and percents of subgroups for 1 or 2 variables. Summarize option gets summary stats for subgroups.

    tabulate race
    tabulate sex ses
    tabulate race ses, summarize(math)
  • summarize - calculates summary statistics such as mean and standard deviation. Detail option gets more statistics and percentiles. By option gets statistics for subgroups.

    summarize rdg wrtg
    by race: summarize rdg wrtg math, detail (note: race must be sorted first)
  • correlate - displays the correlation matrix for a list of variables. Means option gets summary stats for each variable.

    correlate rdg wrtg math sci civ
    correlate rdg wrtg, means
  • regress - fits a linear regression model of a dependent variable on a single predictor or set of predictors. By the time you're done with this class, you'll know what that means.

Top of Page

Graphs

  • graph bar - generates a bar chart
  • histogram - generates a histogram
  • graph twoway - generates a two variable scatterplot
  • graph pie - generates a pie chart

Graphs do not get written to the log files. They must be saved using File-Save Graph

Top of Page

Last Updated: 11/7/13