π Day 1: Introduction to Stata Programming#
Graduate-Level Short Course#
π― Learning Objectives#
By the end of todayβs session, you will be able to:
Navigate the Stata interface and understand its workflow
Execute and interpret basic Stata commands and syntax
Identify and differentiate types of Stata outputs
Begin writing clear, shareable, and modular code
π Pre-Class Survey#
Before we begin, please complete the short entry survey to help us tailor the course to your technical setup and prior experience:
Questions:
How will you access Stata this week?
Locally on your laptop
Remotely (e.g., SSH, RDP, terminal)
Which operating system are you using?
MacOS
Unix/Linux
Windows
Whatβs your experience level with statistical software?
π« No Experience
π Basic Knowledge
π§ͺ Novice User
π οΈ Competent User
π Advanced User
π§ Expert User
1. π Understanding Stata: System vs. User#
graph TD
A[System] --> B[Native Stata]
A --> C[Third-party .ado files]
A --> D[Your .ado files]
E[User] --> F[Known Users]
E --> G[Unknown Users]
Conceptual Distinctions:
System: The core Stata application and official components
User: You, your collaborators, or future analysts using your code
Empathy: Good code anticipates user confusion
Sharing is Caring: Write your code like it will be inherited
2. π₯οΈ Stata Interface Walkthrough#
Key Windows#
Command β β1
Results β β2
History β β3
Variables β β4
Do-file Editor β β9
3. π§ Stata Syntax 101#
Anatomy of a Command#
command [varlist] [if] [in] [, options]
Example:
summarize age if gender == 1, detail
Command Types#
Native β Built-in commands (blue text)
Third-party β Installed via SSC or GitHub (white text)
User-written β Your own
.ado
files
Try it:
display "Hello Stata Programmers!"
4. π Working with Datasets#
Life Expectancy Dataset#
webuse lifeexp, clear
describe
Output Types Visualized#
graph TD
Results --> String
Results --> Numeric
String --> Text
String --> URL
String --> Filepath
Numeric --> Integer
Numeric --> Decimal
Integer --> byte
Integer --> int
Integer --> long
Decimal --> float
Decimal --> double
5. π§ͺ Hands-On Practice#
π Task 1: Country vs Life Expectancy#
webuse lifeexp, clear
encode country, gen(Country)
twoway scatter lexp Country, xscale(off)
graph export lexp_bycountry.png, replace
π² Task 2: Simulated BMI Distribution#
clear
set obs 1000
generate bmi = rnormal(28, 5)
histogram bmi, normal
graph export bmi.png, replace
6. π¨ Debugging Common Errors#
β Unrecognized Command#
myfirstprogram
Output:
command myfirstprogram is unrecognized
r(199);
π οΈ Troubleshooting Checklist#
Check spelling (case-sensitive)
Confirm package installation
Use
help commandname
to review syntaxUse
which commandname
to locate command source
7. β Key Takeaways#
Stata has a structured, predictable syntax
Learn to recognize command types and their origin
Outputs are typed: numeric or string (and more nuanced)
Thoughtful code helps future-you (and others!)
π For Tomorrow#
Install any needed third-party packages (weβll guide you)
Revisit core commands with
help
andsearch
Bring at least one question or observation from today