0% found this document useful (0 votes)
124 views6 pages

STATA Lab 1: Do-files & Data Commands

The document discusses how to use STATA for data analysis and visualization. It covers opening data files in STATA, using do-files to save and document code, and basic commands like describe, browse, and sum to get summary statistics and explore data.

Uploaded by

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

STATA Lab 1: Do-files & Data Commands

The document discusses how to use STATA for data analysis and visualization. It covers opening data files in STATA, using do-files to save and document code, and basic commands like describe, browse, and sum to get summary statistics and explore data.

Uploaded by

Muneeb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Eeman S Qureshi Lab 1

SDA LAB 1: Introduction to STATA, Do-files, Log-files.

What is STATA?

• Descriptive statistics
• Relationship between variables
• Inferential Statistics
• Data Visualizations (Graphs)

STATA INTERFACE:

The file formats STATA can open:

1) Excel format denoted by .xls


2) STATA’s own file format given by .dta.
3) Csv files
Eeman S Qureshi Lab 1

Opening a dta file:

Go to file, open and click on the ‘ess1gb.dta’ to open the data.

Importance of Do-files:

A do-file is a set of codes that tell STATA what commands to run. In other softwares, it is called
program. It is an essential component of using STATA and of data cleaning because in addition to
writing commands in it, the user can also document, make notes, state hypothesis and even make
notes of some of the preliminary results:

 You can save commands in a do-file to replicate later.


 You can also execute the entire do-file again or execute a selection of commands.

How to Open Do-files:

Go to the top left of STATA, you will see a small notepad icon, click on that and a do-file
will open which looks like a notepad.
Eeman S Qureshi Lab 1

How to Open an Excel File:

Use the import command to open this data set, go to file and then click on import excel file to
open this data set: Make sure you select first row as variable names option and go to next.
Eeman S Qureshi Lab 1

How to add comments on a do-file?

Comments are added to a do-file to add context for the reader as well as for you to remember
why you’re performing a particular command. They appear in a green font in the do-file.
 To add comments on the do-file use '*', or '//' for single line comment.
 Start from '/*' and end with '*/' for comments spanning over multiple lines.

Command Rules in STATA:

 Commands should be written in lower case form, if you type them in upper case
letters: STATA will show an error.

BROWSE COMMAND:

We can look at the data in its original form in STATA through command shortcuts or
clicking on the data browser window at the top:

type command ‘browse’

This will open a sheet which shows the data in its raw form.

If you wish to browse specific variables, you can do so by typing the variable names in
front of browse. Let’s suppose we want to see only Name and Mid. Type the following
command in this case:

Browse Name Mid


Eeman S Qureshi Lab 1

DESCRIBE COMMAND:

Let’s run some commands now to get to know the data we have loaded. When we open a data
set, we want to get to know the data and we look to answer three questions:

• Number of observations
• Number of variables
• Type of Variables

We use the command ‘describe’ to do this.

SUMMARY STATISTICS:

If we want to find the summary statistics (mean, std. dev, and number of observations and
minimum and max values) for our variables, we type the following command:

sum

If you want to see the summary statistics for particular variables, just type the variable name
in front of sum. Let’s find out the mean of the Midterm by typing the following command:

sum Mid
Eeman S Qureshi Lab 1

Assignment
Question 1: Open STATA file type 'ess1gb.dta' and provide command in your do-files.

Question 2: Import the ‘gradebook’ excel file in STATA and provide the command in your
do-files. Please add the option clear at the end.

Question 3: For the ‘gradebook’ dataset, please find the number of observations and number
of variables present in your dataset. Type the command you used to reach your answers in
your do-files.

Question 4: For the gradebook dataset, type the command to find the mean of the Final in
your do-files.

You might also like