Setting Up Stata in the WRDS Cloud

Learn how to connect to the WRDS Cloud and set up your Stata working environment.

Before You Begin

Before you can work with Stata software and data in the WRDS Cloud, you must have the following:

  • A valid, active subscription to any WRDS dataset you wish to use
  • A valid, active license for Stata. To obtain a license, see Order Stata
  • An active WRDS account with access to your home directory. For more information, see Storing Your Data on the WRDS Cloud
  • SSH client software (such as PuTTY) installed on your computer. For more information, see Using SSH to Connect to the WRDS Cloud
  • A shell program, such as BASH or TCSH, for accessing the UNIX operating system in the WRDS Cloud

Your WRDS home directory is where you store all your Stata programs and data files. It is located at /home/[your_group name]/[your_username]..

SSH is how you connect to the WRDS Cloud from your computer, and allows you to enter commands and run programs in the WRDS native UNIX environment from a command line window.

If you are unfamiliar with or need to brush up on your UNIX, see UNIX Quick Reference.

Top of Section

Introduction to Stata at WRDS

Stata is an integrated statistical software package popular in various fields of data research, especially in the field of economics.

The following versions of Stata are available in the WRDS Cloud:

  • Stata/IC (stata) - the default version for mid-size datasets
  • Stata/MP (stata-mp) - for multiprocessor environments, ideal for the WRDS Cloud
  • Stata/SE (stata-se) - for large datasets

WRDS recommends the stata-mp version, however there are occasions where the stata or stata-se version may serve you better. For more information, see Which Stata is right for me?

NOTE: The stata-mp version is used for all examples.

Top of Section

Setting Stata Connection Parameters

Using your SSH client, you connect to the WRDS Cloud (see Using SSH to Connect to the WRDS Cloud) and then access data using a secure ODBC connection to a PostgreSQL database.

To connect to the PostgreSQL database, you must first create two files in your WRDS Cloud home directory. This only needs to be done once. Use any text editor, such as UNIX nano or vi, to create these files.

The two files contain the ODBC connection parameters, such as server name, username, and password, so that you do not need to enter them each time you wish to connect to WRDS within Stata.

Once connected, navigate to your home directory and create a new /odbc directory as follows:

To create the odbc directory:

mkdir ~/odbc

While in this new directory, create the first ODBC file as follows and name it odbc.ini.

To create the odbc.ini file:

[ODBC Data Sources]
wrds-postgres = PostgreSQL

[wrds-postgres]
Driver           = PostgreSQL
Description      = Connect to WRDS on the WRDS Cloud
Database         = wrds
Username         = your_wrds_username
Password         = your_wrds_password
Servername       = wrds-pgdata-h.wharton.private
Port             = 9737
SSLmode          = require

Where your_wrds_username is your WRDS username, and your_wrds_password is your WRDS password. Be sure to place this file in the /odbc directory you just created. The file's location should therefore be: ~/odbc/odbc.ini.

As this file contains your WRDS username and password in plain text, it is very important that you restrict permissions on this file using the following command.

This command sets the permissions on this file to be read/write for your user account only.

To restrict file permissions:

chmod 600 ~/odbc/odbc.ini

The second file you need to create depends on what shell your are using - TCSH or BASH. To find out what shell you're running, enter the following from the command prompt:

echo $SHELL

Depending on the response you receive, create the next ODBC file as shown using one of the two following options:

For TCSH shell users

If you are a tcsh shell user, you will create an odbc.csh file in your ~/odbc/ directory. The file's location should therefore be: ~/odbc/odbc.csh.

To create the odbc.csh file for tcsh users:

setenv ODBCINST /etc/odbcinst.ini
setenv ODBCINI $HOME/odbc/odbc.ini

NOTE: The $HOME variable is expanded to the full path to your home directory when you source this file. Stata requires the full path to be able to properly find the odbc.ini file; using the ~ character as a short cut will not work.

For BASH shell users

If you are a bash shell user, you will create an odbc.sh file in your ~/odbc/ directory. The file's location should therefore be: ~/odbc/odbc.sh.

To create the odbc.sh file for bash users:

ODBCINST="/etc/odbcinst.ini"; export ODBCINST
ODBCINI="$HOME/odbc/odbc.ini"; export ODBCINI

NOTE: The $HOME variable is expanded to the full path to your home directory when you source this file. Stata requires the full path to be able to properly find the odbc.ini file; using the ~ character as a short cut will not work.

Top of Section

Next: Running Jobs using Stata

Now that your Stata environment is configured to connect to the WRDS Cloud, you are ready to start Running Jobs using Stata.

Top of Section

Top