You are on page 1of 14

Krishnendu Maji

Assistant Professor of Economics


Goenka College of Commerce and Business Administration
West Bengal Education Service
Setting Working Directory
To View Path of the Current
Working Directory

Preferred Path for Working Directory

To View Files Within Current


Working Directory

display: Use Stata as a Calculator


Reading .csv File in

Path Followed By File Name save: saving data in .dta format


use: import data in .dta format

Variable Name(s)

Condition
To Know More About a
Removing Data Syntax: help <Syntax>

To know more about data structure


Importing Data
(Other File Formats)
Excel File Format:

Tab Delimited File Format:

Specifying Delimiters

Specific Delimiter
Frequency Distribution:
One-way tables of frequencies
Syntax: tabulate or tab

Conditional Operators
Distribution of a Condition Symbol Meanings
Categorical Variable (Optional) > Greater than
< Less than
OR >= Greater than and
equal to
<= Less than and equal to
& and
| or
Sorting Categorical Categorical Variable == Equal to
Variable ! Not
~= OR != Not equal to
Sorting Data & Alternative to Syntax: bysort
Sort by 1st variable followed by 2nd variable

Application of Syntax: order


Category wise applying a
function (Alternative to syntax:
bysort)
Frequency Distribution:
Two-way tables of frequencies
Syntax: tabulate or tab

Categorical Variables Condition


(Optional)

For Row & Column


Percentages Respectively
(Optional)
Summary statistics
Syntax: summarize OR su

Specifying Variable(s) Condition Detail Summary


(Optional) (Optional)

Category Wise Summary of


Numeric Variable(S)
Create or change contents of variable
Syntax: generate OR gen

Algebraic Operators
New Variable Mathematical Existing Syntax Meanings
Name Function Variable
+ Addition or
Mathematical Functions Concatenation
- Subtraction
Some other functions Functions Syntax
Square root sqrt()
/ Divission
Functions Syntax Exponential exp() * Multiplication
If Function cond() Log base 10 log() ^ Powering
String substr() Lag base e ln()
Function
Obs. No. _n
Creation of Dummy variable
Syntax: generate OR gen

Data Generation Condition


(Optional)

Followed By:

Data cleaning can also be performed using ‘replace’ syntax


Renaming & Labeling Variables:
Syntax: rename & label

Existing Variable Name New Variable Name


Old Value Followed By
Variable Name New Label
Keeping & Dropping Variables:
Syntax: keep & drop

Variable Names(s) Condition(s)

Dropping & Keeping Dropping & Keeping


Variables Observations
Display table of summary statistics:
Syntax: tabstat

Variable Names(s) Categorical Statistics


Variable
Other Concepts
 Macros: Use of .do files (Automation)
 Log Files (Storing Results)

Syntax Input Options Explanations


do <dofile name with location> Open Do-file Editor
log using <dofile name with location> replace, Open a log file, replacing the old
append one if it already exists
log close Close a log file

You might also like