ECO601 — Final Term Summary (Lectures 23–45)
📘 Lecture 23 — Estimating Non-Linear equation by OLS
📖 Overview: This lecture covers how to estimate non-linear relationships using Ordinary Least Squares (OLS) by introducing polynomial terms and logarithmic transformations. It explains the methodology for estimating quadratic, cubic, and Cobb-Douglas production functions, along with the interpretation of different functional forms and key diagnostic checks.
🗂️ Topics Covered
Estimating quadratic equations by OLS with U-shaped and inverted U-shaped curves; derivation of normal equations; practical example using Excel's LINEST function and centering X to reduce multicollinearity; estimation of cubic equations for functions like total cost; derivation of normal equations for four parameters; transformation and estimation of the Cobb-Douglas production function using logs; a comprehensive table of transformations and interpretation of different functional forms (linear, double-log, level-log, log-level); and a checklist of seven critical questions to evaluate OLS models.
📝 Lecture Summary
Estimating Quadratic Equation by OLS
Quadratic equations capture U-shaped (convex) or inverted U-shaped (concave) relationships between variables. To estimate such relationships, we include the square of the independent variable in the regression. For U-shaped (convex) curves, the coefficient of the quadratic term is positive. For inverted-U-shaped (concave) curves, the coefficient of the quadratic term is negative.
The quadratic equation (ignoring subscripts) is: 풀 = 풂 + 풃푿 + 풄푿² + 풆
To find the parameters a, b, and c, we minimize the sum of squared residuals: Min Z = Σ풆² = Σ(푌 − 푌̂)² = Σ(풀 − 풂 − 풃푿 − 풄푿²)²
Taking partial derivatives and setting them to zero yields three normal equations:
- Σ푌 = 푛푎 + 푏Σ푋 + 푐Σ푋²
- Σ푋푌 = 푎Σ푋 + 푏Σ푋² + 푐Σ푋³
- Σ푋²푌 = 푎Σ푋² + 푏Σ푋³ + 푐Σ푋⁴
The practical approach uses Excel's LINEST function.
📌 Example I: Given data for Y and X (n=15), the LINEST output provides coefficients. The estimated regression line is: Y = 18.26 - 4.01934 X + 0.44 X² The SSR from a linear equation is 930.5107.
Example I Modified: Centering X
When X is centered (x = X - X̄), the correlation between x and x² becomes zero, eliminating multicollinearity. This improves prediction accuracy. The estimated regression line is: Y = 14.51 - 3.082 x + 0.44 x² The correlation between X and X² is 0.97, but between x and x² it is 0.
📌 Example II: Another dataset yields a concave relationship with a negative quadratic term. The LINEST output gives: Y = 48.97 + 5.099 X - 0.4955 X² The SSR from a linear equation is 1308.171.
Estimating Cubic Equation by OLS
Cubic equations model relationships like the Total Cost function. For this shape, the coefficient of the quadratic term is expected to be negative and the coefficient of the cubic term should be non-zero.
The cubic equation is: 풀 = 풂 + 풃푿 + 풄푿² + 풅푿³ + 풆
Minimizing the sum of squared residuals leads to four normal equations:
- Σ푌 = 푛푎 + 푏Σ푋 + 푐Σ푋² + 푑Σ푋³
- Σ푋푌 = 푎Σ푋 + 푏Σ푋² + 푐Σ푋³ + 푑Σ푋⁴
- Σ푋²푌 = 푎Σ푋² + 푏Σ푋³ + 푐Σ푋⁴ + 푑Σ푋⁵
- Σ푋³푌 = 푎Σ푋³ + 푏Σ푋⁴ + 푐Σ푋⁵ + 푑Σ푋⁶
📌 Example: Using given Y and X (n=15), the LINEST output for a cubic function yields: Y = 1023.7 + 221.87 X - 1.306 X² + 0.00000984 X³ The SSR from a linear equation is 45562.33.
Estimating Cobb-Douglas Production Function
The Cobb-Douglas Production Function is: 푄 = 퐴 푙^α 푘^β
By taking natural logs, it becomes linear in parameters: ln 푄 = ln 퐴 + α ln 푙 + β ln 푘
Letting 푌 = ln 푄, 훼 = ln 퐴, 퐿 = ln 푙, 퐾 = ln 푘: 푌 = 훼 + α 퐿 + β 퐾
This linear form can be estimated by OLS.
📌 Example: Given output (Y), labor (L), and capital (K) data, the log-transformed variables produce OLS estimates. The estimated function is: ln Y = 0.283 + 0.41 ln L + 0.32 ln K
- Elasticity (labor) = 0.41 (a 1% change in labor leads to a 0.41% change in output)
- Elasticity (Capital) = 0.32
- Returns to scale = 0.73 (sum of elasticities; less than 1 indicates decreasing returns to scale)
Transformation of models and Use of OLS
| Method | Transformation | Regression equation |
|---|---|---|
| Standard linear | Not required | y = b + b x |
| Exponential model | Dependent variable = log(y) | log(y) = b + b x |
| Logarithmic model | Independent variable = log(x) | y = b + b log(x) |
| Double log | Dependent & Independent = log(y), log(x) | log(y) = b + b log(x) |
| Cobb Douglas | ln Y = ln A + α ln L + β ln K | ln Y = ln A + α ln L + β ln K |
Interpretation of different functional forms using OLS
| Model | Interpretation | Marginal Effect | Elasticity |
|---|---|---|---|
| Linear in variable Y = a + bX | One unit change in X causes 'b' units change in Y | b | b * (X/Y) |
| Double log form (log-log) | One percent change in X causes 'b' % change in Y | b * (Y/X) | b |
| Level-Log Y = a + b ln X | One percent change in X changes Y by b/100 units | b/X | b/Y |
| Log-Level form ln Y = a + b X | One unit change in X changes Y by (b*100)% | bY | bX |
For interpretation, we assume Gauss-Markov assumptions hold and parameters are significant. The marginal effect of X is the partial derivative of Y w.r.t. X. Marginal effect and elasticity (dy/dx * X/Y) may be computed at mean values of X and Y.
Problems with OLS
We must take care of:
- Outliers
- Non-linearity
- Wrong specification
- Missing Variables
- Multicollinearity
- Heteroskedasticity
- Autocorrelation
Taking care in use of OLS: 7 Questions
- Are the explanatory variables helping the model?
- Are the relationships what we expect?
- Are any of the explanatory variables redundant?
- Are the residuals normal?
- Have all important variables been included?
- How well the model explains the dependent variable?
- Are the results free from Multicollinearity, Heteroskedasticity, and Autocorrelation?
Remember:
- Explanatory variables can have categories.
- We can use dummy variables for categories.
- If the dependent variable is categorical, do not use simple regression.
- Take care of origin and scale for interpretable coefficients.
- Models not linear in parameters cannot be transformed for OLS.
💡 Why this matters: Understanding how to estimate non-linear relationships allows you to model real-world economic phenomena like cost curves, production functions, and diminishing returns that cannot be captured by simple linear models.
⭐ Key Takeaways
Estimating non-linear equations with OLS requires introducing polynomial terms (squares, cubes) or taking logarithmic transformations. For quadratic equations, the sign of the squared term determines whether the curve is U-shaped (positive) or inverted U-shaped (negative). Centering the X variable eliminates multicollinearity between X and X². The Cobb-Douglas production function is linearized by taking natural logs of both sides, and the coefficients directly represent elasticities (labor elasticity and capital elasticity), with their sum indicating returns to scale. Different functional forms (linear, log-log, level-log, log-level) have distinct interpretations for marginal effects and elasticities. Finally, always evaluate a model using seven diagnostic questions about variable significance, expected signs, normality, specification, explanatory power, and freedom from multicollinearity, heteroskedasticity, and autocorrelation.
🧠 Quick Revision Questions
- What is the sign of the coefficient of the quadratic term for a U-shaped (convex) curve?
- Write down the three normal equations needed to estimate a quadratic regression equation by OLS.
- What is the advantage of centering the independent variable X in a quadratic regression?
- For a Cobb-Douglas production function estimated as ln Y = 0.283 + 0.41 ln L + 0.32 ln K, what are the labor elasticity and returns to scale?
- If the model is ln Y = a + bX, how do you interpret the coefficient 'b'?
📘 Lecture 24 — Introduction to Stata- I
📖 Overview: This lecture introduces the Stata statistical software environment, its interface components, file types, and basic commands. It covers how to navigate Stata's graphic user interface and command window, open different types of data files, and use essential commands like help, describe, and list to explore datasets. This foundational knowledge is critical for conducting econometric analysis in Stata.
🗂️ Topics Covered
The lecture begins with an overview of the Stata environment showing five windows: output, command, variable, properties, and review. It then discusses file types used in Stata including .dta, .log, and .do files, and three types of data files. The graphic user interface and command window are explained with their advantages. The help command syntax and structure are covered in detail, followed by methods for opening files. Finally, the describe and list commands are explained with their three usage patterns and examples.
📝 Lecture Summary
The Stata Environment
The Stata interface consists of five visible windows. The main window (output window) displays all output. Below it is the command window where users type and execute commands. While Stata has a good graphic user interface, the command line allows for quick and efficient work. On the right side, the variable window displays all variables, and below it the properties window shows variable properties like names, storage types, and display format. The review window on the left displays all commands executed in the current session; clicking any command executes it again without retyping.
Several file types are used in Stata:
- Data files have extension .dta (can type without extension)
- Log files record sessions (.smcl or .log)
- Do files perform multiple operations at once (.do)
🔑 Definition — .dta files: The data file format used by Stata for storing datasets.
Types of Data Files (.dta)
There are three types of data files:
• Sample data files shipped with Stata (opened by sysuse command)
• Files available on the web (using the webuse command)
• Files created and saved on hard disk (using use command)
Other data files (like MS Excel) can be imported into Stata.
💡 Why this matters: Knowing which command to use for different data sources allows efficient access to datasets for analysis.
The Graphic User Interface
A strong graphic user interface (GUI) is available where operations can be performed by clicking on different icons. This is very user friendly and allows users to perform operations without typing commands.
The Command Window
The command window allows typing and executing different commands. All operations available through the GUI can be performed in the command window. This is undoubtedly a very quick way of using Stata.
Advantages of using the command window: • Typing commands is less time consuming • You remember the commands this way • It may be helpful if you need to program in Stata
Rules for commands:
• Use small letters; Stata is case sensitive
• Short names can be used (e.g. d / des instead of describe)
• Syntax can be viewed in the help window
• Underlined part in the syntax is the shortcut
• Commands have options (after typing comma ,)
• Conditions can be used with commands (e.g. if, in etc.)
The 'help' Command
The syntax for the help command is:
🔑 Formula: help [command or topic] [,options]
The underlined part is the minimum that should be typed for help. For example, typing h describe opens a window showing help for 'describe'.
From the graphic user interface: Help > Stata Command... and write the command in the window that appears.
Typing 'help help' opens a help window explaining the help command itself. Typing 'help describe' opens the help window for describe. Almost all help windows have the same structure: they show the command, its shortcut, its syntax, description, and practical examples of use.
Opening Files in Stata
To open different types of files:
- Sample data files shipped with Stata: Type
sysuse filenamein the command window - Files on the web: Type
webuse filename - Files on hard disk: Use
use "path and file name"oruse "path and file name", clear
The ,clear option can be used to clear existing data from memory before opening a new file.
To open a file using the graphic user interface: File > Open (browse, find file, and open)
To know which files are already available with Stata, type sysuse dir. A list of files will appear in the output window. Any one of them can be opened. For example, to open the first file, type sysuse auto.
📌 Example: sysuse auto opens the auto dataset. A message appears in the output window, variables appear in the variable window, variable descriptions appear in the properties window, and all typed commands appear in the review window.
The describe Command
The describe command provides a description of data in the current file. It lists the variables, labels, formats, storage type, number of observations, and date the file was created.
It can be used mainly in three ways:
• describe: describes all variables in memory
• describe variable-names: describes only the specified variables
• describe variable1-variablen: describes all variables in the range
To use the graphic user interface: Data > Describe data > Describe data in memory or in a file. A window appears asking for variable names (use pull-down menu if file is open).
📌 Example: The command sequence sysuse auto then describe produces output showing variable names, data type, display type, and any labels. This gives the current file at a glance with all variables.
📌 Example: describe mpg price describes only the variables mpg and price.
📌 Example: describe price - length describes all variables from price through length (the range).
The list Command
The list command lists rows and columns of the data file. It provides the values of observations of data.
It can be used mainly in three ways (same pattern as describe):
• list: lists values of all variables in memory
• list variable-names: lists values of only the specified variables
• list variable1-variablen: lists values of all variables in the range
To use the graphic interface: Data > Describe data > List data. A window appears asking for variable names using the pull-down menu. Select variables and click OK.
Using list with in and if:
Conditions can be imposed for filtered data to be displayed (using if). Specific rows of data can be displayed (data in specific rows). Conditions also may be attached.
⭐ Key Takeaways
The Stata environment has five key windows: output, command, variables, properties, and review. Data files (.dta) come in three types—shipped with Stata (sysuse), web-based (webuse), and local files (use). The command window is faster than GUI, requires lowercase case-sensitive commands, and allows shortcuts (the underlined part of syntax). The help command shows syntax, description, and examples for any Stata command. The describe command reveals dataset structure (variables, types, labels, observations), while the list command displays actual data values, both supporting three usage patterns (all, specific variables, or ranges) with optional conditions using in and if.
🧠 Quick Revision Questions
- What are the five windows in the Stata environment and what is the function of each?
- What are the three types of .dta files and which command opens each type?
- What is the syntax for the help command and how can you find the shortcut for any command?
- What information does the describe command provide and what are its three usage patterns?
- How does the list command differ from the describe command, and how can conditions like
inandifbe used with it?
📘 Lecture 25 — Introduction to Stata- II
📖 Overview: This lecture introduces additional Stata commands for summary statistics and frequency tables. It covers how to use
summarizewith options,tabulatefor one-way and two-way tables,tabstatfor customized summary statistics, andcorrelatefor correlation/covariance matrices — essential tools for exploratory data analysis in econometrics.
🗂️ Topics Covered
The lecture covers five main Stata commands: summarize with syntax and options, tabulate for one-way and two-way frequency tables, tab1 for multiple one-way tables, tabstat for flexible summary statistics with the by() and stats() options, and correlate for correlation and covariance matrices. Each command is demonstrated using the auto dataset with examples.
📝 Lecture Summary
The summarize Command
The summarize command provides summary statistics for numeric variables. Its syntax is:
summarize [varlist] [if] [in] [weight] [, options]
From the menu: Statistics > Summaries, tables, and tests > Summary and descriptive statistics > Summary statistics
If the file auto is open (sysuse auto), summarize gives summary statistics of all variables in the file. Like previous commands, it can be used standalone, with specific variables, or with a range of variables.
📐 EXAMPLES:
summarize— summary for all variablessummarize price mpg length— for specific variablessummarize price-length— for a range of variables
💡 Why this matters: The ability to quickly generate descriptive statistics is fundamental for any data analysis project. The in and if qualifiers allow you to subset your data, which is essential when working with large datasets.
The tabulate Command
The tabulate command provides one-way or two-way frequency tables. Its syntax is:
tabulate varname [if] [in] [weight] [, tabulate1_options]
From the menu: Statistics > Summaries, tables, and tests > Frequency tables > One-way table
The command requires a variable name. It can be used with the summarize option to get summary statistics by categories:
tabulate foreign, summarize(mpg)
This provides summary statistics of mpg according to categories in foreign. All options in Stata must follow a comma.
🔑 Definition — tabulate options: Options like summarize() are used after a comma to modify the tabulate command's output. The summarize() option produces summary statistics of a specified variable broken down by the categories of the tabulated variable.
Tabulating Multiple Variables — tab1
The tab1 command allows tabulating multiple variables in one command. For example, to get frequency tables for rep78 and foreign in the auto file, you would type:
tab1 rep78 foreign
This is more efficient than running separate tabulate commands for each variable.
Two Way Frequency Tables
Two-way tables can be created with tabulate when two variable names are specified. For this to work well, at least one variable should not have many categories. The example in the lecture produces a two-way table (the output image shows cross-tabulation of two variables).
💡 Why this matters: Two-way tables are essential for exploring relationships between categorical variables, such as whether foreign cars have different repair records than domestic ones.
The tabstat Command
The tabstat command displays summary statistics for a series of numeric variables. It is a good alternative to summarize because it allows you to specify the list of statistics to be displayed. Its syntax is:
tabstat varlist [if] [in] [weight] [, options]
From the menu: Statistics > Summaries, tables, and tests > Other tables > Compact table of summary statistics
📐 EXAMPLES:
tabstat price mpg weight— provides means (default) of the specified variablestabstat price mpg weight, stats(mean sd min max)— provides mean, standard deviation, minimum, and maximumtabstat price mpg, by(foreign)— provides statistics by categories of a variabletabstat price mpg, by(foreign) stats(mean sd n)— combines both options
🔑 Definition — stats() option: An option in tabstat that specifies which summary statistics to display (e.g., mean, sd, min, max, n). Without it, only means are shown.
💡 Why this matters: tabstat gives you precise control over the summary statistics you want to see, which is very useful when you need specific measures (like standard deviations or counts) for a research paper.
The correlate Command
The correlate command provides the correlation or covariance matrix of the specified variables. Its syntax is:
correlate [varlist] [if] [in] [weight] [, correlate_options]
From the menu: Statistics > Summaries, tables, and tests > Summary and descriptive statistics > Correlations and covariances
📐 EXAMPLES:
correlate price mpg weight— displays the correlation matrix- To get summary statistics along with correlations, use
summarizefollowed bycorrelate:summarize price mpg weight correlate price mpg weight - Use the
covarianceoption to get the covariance matrix instead of correlations
🔑 Definition — correlation matrix: A table showing correlation coefficients between variables, ranging from -1 to +1, indicating the strength and direction of linear relationships. The covariance matrix shows covariances instead.
⭐ Key Takeaways
The most critical commands introduced are summarize, tabulate, tabstat, and correlate, each serving specific descriptive analysis purposes. summarize provides quick summary statistics of numeric variables, with options to use if, in, and variable ranges. tabulate creates one-way or two-way frequency tables and can include the summarize() option for grouped summary statistics, while tab1 allows multiple one-way tables in one command. tabstat is the most flexible command for summary statistics as it lets you specify exactly which statistics to display using the stats() option and can break results down by categories using by(). Finally, correlate generates correlation or covariance matrices, essential for understanding relationships between variables, with the covariance option providing the covariance matrix instead.
🧠 Quick Revision Questions
- What is the syntax of the
summarizecommand, and how can you restrict it to only variablesprice,mpg, andlength? - What is the difference between
tabulateandtab1commands in Stata? - How would you produce the mean, standard deviation, and count of
priceandmpgbyforeignusingtabstat? - What does the
correlatecommand produce by default, and how can you change it to produce a covariance matrix? - In the command
tabulate foreign, summarize(mpg), what does thesummarize(mpg)option do?
📘 Lecture 26 — Introduction to Stata- III
📖 Overview: This lecture covers essential data management techniques in Stata, including how to import data from various file formats, create and modify variables, and manage dataset metadata. Understanding these skills is crucial for efficiently preparing and cleaning data for econometric analysis.
🗂️ Topics Covered
The lecture covers importing data from Excel and other file formats, entering data manually, rules for variable naming, creating and modifying variables using generate and replace commands, arithmetic and logical operators, mathematical functions, assigning variable and data labels, creating notes, dropping or keeping variables and observations, and using log files and do files to document and automate work.
📝 Lecture Summary
Data Management in Stata
This section introduces the core data management capabilities in Stata, which are essential for preparing datasets for analysis. It covers importing data from external sources, entering data manually, and understanding the conventions for naming variables.
Importing Data
Data can be imported into Stata from various types of files including Microsoft Excel files, raw data files, text files, csv files etc. Several commands are available for importing data: import excel is used for .xls or .xlsx files with the syntax import excel [using] filename [, import_excel_options]. Other commands include infix for fixed format files, infile for free format files, insheet to import ASCII text data, and input to enter data from the keyboard. To import an Excel file, you can use the menu path: File > Import > Excel spread sheet (or others), then browse for the file, select "import variables names as first row", and click OK.
Entering Data Data can be entered directly by clicking on the icon 'data editor (edit)' and then entering data as you would in Excel. Variable names can be changed within this editor.
Variable Names
Variable names in Stata must follow specific conventions: they can be up to 32 characters (12 displayed), can include 0 to 9, A to Z, and underscore (_), the first letter cannot be a number, and variable names are case sensitive. Valid examples include mpg, mpg2, mpg_domestic, and _2014. The Variable manager is used to change variable names, or you can use the rename command (rename oldname newname).
Creating Variables
Variables are created and/or modified using the generate and replace commands.
The generate command creates a new variable. The value of the new variable is given by the =exp. Its syntax is: generate [type] newvar[:lblname] =exp [if] [in]. The command can also be executed using the menu: Data > Create or change data > Create new variable, then fill in the required information.
🔑 Definition — generate: Creates a new variable in the dataset.
📌 Example: generate income = 0 creates a new variable named income with all values set to 0.
📌 Example: gen income = salary + bonus creates a new variable that is the sum of two existing variables.
📌 Example: gen int agesquare = age^2 creates a new integer variable that is the square of the age variable.
📌 Example: gen lngdp = ln(gdp) creates a new variable containing the natural log of the gdp variable.
The replace command
The replace command is used along with generate to modify existing variables. It has the syntax: replace oldvar =exp [if] [in] [, nopromote]. Using the in qualifier is helpful for targeting specific observations. From the menu, you can click: Data > Create or change data > Change contents of variable, then fill in the variable name and use the if/in ribbon to type a condition.
📌 Example: replace income = 1 in 5 changes the income value for the 5th observation to 1.
📌 Example: replace income = 1000 if income == 0 replaces all income values that equal 0 with 1000.
📌 Example: replace highincome = 1 if income > 5000 sets highincome to 1 for all observations where income exceeds 5000.
📌 Example: gen age2 = 0 followed by replace age2 = age^2 creates a new variable then fills it with squared ages.
📌 Example: replace age2 = age^2 , nopromote replaces values without promoting the variable type.
Operators in stata
The following operators are commonly used in Stata:
- Arithmetic: + (add), - (subtract), * (multiply), / (divide), ^ (raise to a power), + (for strings)
- Logical: ! or ~ (not), | (or), & (and)
- Relational: == (equal), != or ~= (not equal), < (less than), > (greater than), <= (less than or equal to), >= (greater than or equal to)
Functions
Type help mathfun to see all functions. Common examples include:
abs(x)– Absolute value of xint(x)– Integer of xlog(x)– Logarithmsqrt(x)– Square root of xround(x)– Round x to the nearest integer
Assigning labels to variables
Variable labels are useful for understanding what variables contain. Labels provide data labels and variable labels, which are helpful in understanding the data. Use the label variable command for assigning labels to variables. To label the dataset as a whole: label data ["label"] (e.g., label data "1978 Automobile Data"). To create variable labels: label variable varname ["label"] (e.g., label variable make "Make and Model").
Creating Notes
The note command places a note in the data, which can be general or attached to a specific variable. To create notes for a variable: notes [evarname]: text. For example: note make: this is a note for variable make. To see the note, type note make. To create general notes: note: this version is from June 2014. To see general notes, type notes or notes _dta.
Dropping or Keeping Variables
The commands drop and keep are used to drop specific rows of data or entire variables.
- To drop variables:
drop varlist - To drop observations:
drop if exp - To drop a range of observations:
drop in range [if exp] - To keep variables:
keep varlist - To keep observations that satisfy a specified condition:
keep if exp - To keep a range of observations:
keep in range [if exp]
Using log files and do files
Log files are used to record your session, using .smcl, .log, or .txt extensions depending on needs. Do files are used to run several commands at a time or replicate results. To open log files, click the notepad-like icon on the menu. You can create files with .smcl or .log extensions (the latter can be opened in Notepad). Log files record all your activity; you can suspend them to stop recording and resume later, and finally close them to view later. Do files (.do extension) are text editor files that can execute several commands at a time. Click the corresponding icon to open a do file, type a list of commands, and execute them all at once.
💡 Why this matters: Mastering log and do files ensures reproducibility of your analysis, allowing you to efficiently rerun complex analyses and share your work with others.
⭐ Key Takeaways
Students must remember the commands for importing data (especially import excel), the rules for valid variable names, and how to use generate and replace to create and modify variables. The correct syntax for arithmetic, logical, and relational operators, along with common mathematical functions like log() and sqrt(), are essential for data transformation. Understanding how to assign labels and create notes improves data documentation, while the drop and keep commands are critical for subsetting data. Finally, using log files for recording sessions and do files for automating analysis is vital for replicable research.
🧠 Quick Revision Questions
- What Stata command would you use to import an Excel file named "sales.xlsx"?
- Explain the difference between the
generateandreplacecommands, providing an example of each. - What is the purpose of the
label variablecommand, and how is it used? - How does the
dropcommand differ from thekeepcommand when used withifconditions? - What are the two types of files discussed for recording and replicating your Stata work, and what is the main purpose of each?
📘 Lecture 27 — Introduction to Stata- IV
📖 Overview: This lecture introduces students to Stata’s graphical capabilities, covering how to create various types of graphs including histograms, pie charts, scatter plots, and line plots. It emphasizes both menu-driven and command-line methods for producing publication-quality graphics, which is essential for visualizing economic data.
🗂️ Topics Covered
The lecture covers creating histograms for continuous and categorical variables with options like normal curves and grids; constructing pie charts with labels and titles; generating two-way graphs including scatter plots with fitted lines and by-group comparisons; and producing line plots and connected plots using built-in Stata datasets.
📝 Lecture Summary
Introduction to Stata’s Graph Capabilities
Stata has a very good capability to produce graphs with the following properties:
- Rich set of tools
- Publishable quality of graphs
- GUI / Command line both
- Graph Editor
- Graphs can be copied/saved
You can create graphs by clicking on: Graphics menu option.
Examples
Histograms
We can create Histograms for both continuous and categorical variables.
🔑 Definition — Histogram: A graphical representation showing the distribution of numerical data by grouping data into bins (bars) whose height represents frequency or density.
Syntax: histogram varname [if] [in] [weight] [, [continuous_opts | discrete_opts] options]
From the menu: Graphics > Histogram
💡 Why this matters: Histograms help identify the shape, center, and spread of a variable’s distribution, which is fundamental for exploratory data analysis.
EXAMPLES:
-
Basic histogram of price:
sysuse auto histogram price -
Histogram of length:
sysuse auto histogram length -
Histogram with normal curve:
sysuse auto histogram rep78, discrete normalThe option
discretetells Stata the variable is categorical, andnormaloverlays a normal distribution curve. -
Histogram with frequency labels, grids, and custom axis:
sysuse auto histogram mpg, discrete freq addlabels ylabel(,grid) xlabel(10(5)40)freqshows frequencies instead of densitiesaddlabelsadds value labels on top of barsylabel(,grid)adds horizontal grid lines on the y-axisxlabel(10(5)40)specifies x-axis labels from 10 to 40 in steps of 5
PIE Charts
🔑 Definition — Pie Chart: A circular statistical graphic divided into slices to illustrate numerical proportion, where the arc length of each slice is proportional to the quantity it represents.
Syntax: graph pie varlist [if] [in] [weight] [, options]
Menu: Graph > Pie
EXAMPLES:
- Pie chart showing proportion of cars by repair record:
sysuse auto graph pie, over(rep78) plabel(_all name) title("Repair Record 1978")over(rep78)splits the pie by categories of rep78plabel(_all name)labels each slice with the category nametitle()adds a title to the graph
📌 Example: This produces a pie chart with slices for each repair record value (1, 2, 3, 4, 5), each labeled with its name.
-
Creating a pie chart from manually entered data:
graph pie Statistics Mathematics Economics Accounting LawThis uses variable names directly as categories.
-
Pie chart with all data and percentage labels:
graph pie _all , plabel(_all name) title("Distribution of marks")_alluses all numeric variables in the dataset to create the pie slices.
Two way graphs
When more than one variable is involved, we create twoway graphs like scatter plots.
Creation Methods:
- Menu: Graphics > Twoway graph
- Click on Create to define the plot type (e.g., scatter)
- Select the variables and click Accept
- Use ribbons to select titles for axes
Command syntax: twoway (scatter yvar xvar) [, options]
Examples of Scatter Plots (first type sysuse auto, clear to open the file auto.dta):
-
Basic scatter plot with axis and title labels:
twoway (scatter price length), ytitle(Price) xtitle(Length) title(Price and Length)This creates a scatter plot with Price on y-axis and Length on x-axis, with labeled axes and a title.
-
Scatter plot separated by car type (domestic vs. foreign):
twoway (scatter price length), by(foreign)The
by(foreign)option creates separate scatter plots for each category of the variable 'foreign'. -
Scatter plot separated by repair record:
twoway (scatter price length), by(rep78)Creates separate scatter plots for each value of rep78.
-
Scatter plot with fitted linear regression line:
twoway (scatter price length) (lfit price length)scatter price lengthcreates the data pointslfit price lengthadds a linear fit (regression) line
-
Scatter plot with fitted line, separated by car type:
twoway (scatter price length) (lfit price length), by(foreign)This produces two separate scatter plots (domestic and foreign), each with its own fitted regression line.
LINE plots
🔑 Definition — Line Plot: A graph that connects data points with straight lines, typically used to display trends over time or ordered sequences.
Syntax: [twoway] line varlist [if] [in] [, options]
Usage: Using the menu, Line plots are created in the same way as scatter plots. Dataset: Open the file sp500 which is a file available with Stata.
EXAMPLES:
-
Line plot of opening price over date:
sysuse sp500 twoway (line open date)This plots the 'open' variable (opening price) against 'date', creating a time series line graph.
-
Connected scatter plot (points connected by lines):
sysuse sp500 twoway (connected close date)The
connectedoption shows individual data points connected by lines, useful for showing both individual values and trends.
⭐ Key Takeaways
The most critical points to remember from this lecture are: Stata enables creation of publication-quality graphs through both menu-based (Graphics menu) and command-line methods. For histograms, use the histogram command with options like discrete, normal, freq, addlabels, and custom axis labels/ticks. For pie charts, use graph pie with over() for categorical breakdowns and plabel() for slice labeling. Two-way graphs (like scatter plots) use the twoway framework, allowing multiple plot types to be combined — e.g., twoway (scatter y x) (lfit y x) adds a linear fit line. The by() option creates separate graphs for each category of a grouping variable. Line plots use the line or connected commands and are ideal for time series data.
🧠 Quick Revision Questions
- What command creates a histogram with a normal curve overlay, and which option enables this?
- How do you create a pie chart showing proportions of a categorical variable with labels on each slice?
- Write the Stata command to create a scatter plot of 'mpg' vs. 'weight' with a linear fit line.
- What does the
by(foreign)option do when added to a twoway graph command? - Which command and dataset would you use to create a line plot of stock opening prices over time?
📘 Lecture 29 — Introduction to Stata- VI
📖 Overview: This lecture provides a comprehensive step-by-step guide to performing regression analysis in Stata using the
regresscommand. It covers pre-regression data exploration, running the model, conducting post-regression diagnostics (normality, heteroskedasticity, multicollinearity, specification errors, autocorrelation), and applying remedies such as robust standard errors and the Prais-Winsten estimator.
🗂️ Topics Covered
The lecture begins with the syntax and menu-based approach for the regress command, followed by a step-by-step example using the auto.dta dataset, including scatter plots with fitted lines and a correlation matrix. It then covers running a multiple regression model, generating predicted values and residuals, checking residual normality, transforming the dependent variable using inverse and ladder/gladder commands, and finally performing post-regression tests for heteroskedasticity (IM test, hettest), multicollinearity (VIF), model specification (linktest, ovtest), and autocorrelation (Durbin-Watson test), concluding with remedies for heteroskedasticity and autocorrelation.
📝 Lecture Summary
Regression with Stata
Regression analysis in Stata is mainly done by the regress command. The syntax is: regress depvar [indepvars] [if] [in] [weight] [, options]. The menu can also be used via Statistics > Linear models and related > Linear regression, which opens a window to specify the dependent and independent variables.
STEP by STEP example of regression
First, open the file auto.dta using sysuse auto, clear. Summarize and analyze the data, then look at various two-way graphs. Use graph matrix price mpg length weight, half to see pairwise scatter plots. To get a scatter with a line fit, use: twoway (scatter price weight) (lfit price weight) and twoway (scatter price mpg) (lfit price mpg). These graphs help visualize relationships between variables.
Now perform a regression using the command: regress price rep78 weight foreign. The output shows standard regression results that have the usual interpretation (as done with Microsoft Excel). Another example: regress price mpg length foreign.
Post regression Analysis
Use the predict command to get trend values and residuals:
predict phatcreates the variablephat(predicted values).predict e, residualcreates the variablee(residuals).list price phat e in 1/20shows the first 20 observations.
Check if the residuals follow the assumption of normality using histogram e,normal. If residuals are not normally distributed, one reason could be that the dependent variable is not normally distributed. Check the distribution of price with histogram price, normal.
Transform the variable price
We can transform the variable price to achieve normality. The ladder and gladder commands help identify transformations. gladder price produces histograms for various transformations (log, inverse, square, etc.). The inverse and 1/square transformations show the smallest chi-square values.
Generate the inverse of price: gen priceinv=1/price. Then run regression: reg priceinv mpg length foreign. Generate new residuals: predict e1, residual. Check normality: histogram e1, normal. The residuals from regressing the inverse of price look somewhat normal.
💡 Why this matters: Transforming the dependent variable can help meet the normality assumption of OLS regression, leading to valid inference.
Post regression tests
Testing for Heteroskedasticity:
- IM TEST (White Test): returns a test indicating presence of heteroskedasticity.
- hettest: also shows evidence of heteroskedasticity.
🔑 Definition — Heteroskedasticity: When the variance of the error terms is not constant across observations, violating OLS assumption.
Testing for Multicollinearity:
- Use the VIF (variance inflation factor) command. If VIF values are less than 5, there is no multicollinearity detected.
🔑 Definition — VIF: Measures how much the variance of an estimated regression coefficient increases if predictors are correlated. VIF < 5 generally indicates no serious multicollinearity.
Model Specification Tests:
- linktest: performs a model specification test. The null hypothesis is that the model is specified correctly. If the variable
_hatsqis significant, the model is not specified correctly. - ovtest: tests for missing variables. Significant result suggests there may be missing variables in the model.
Testing for Autocorrelation:
Autocorrelation is normally a time series phenomenon. Open a time series data file: webuse klein, clear, set time series: tsset yr, run regression: regress consump wagegovt, then perform Durbin-Watson test: estat dwatson. If the p-value for F is less than 5%, we reject H0 (no autocorrelation).
🔑 Definition — Autocorrelation: Correlation of error terms across time periods, violating OLS assumption in time series data.
REMEDIES for Heteroskedasticity
White developed an estimator for standard errors that is robust to the presence of heteroskedasticity. Use the robust option with regression:
- Run
reg price mpg length foreign(using original price) — errors will be heteroskedastic. - Then run
reg price mpg length foreign, robust— standard errors change, coefficients remain the same.
Remedy for Autocorrelation
Run the analysis with the Prais-Winsten command, specifying the Cochran-Orcutt option. After iterations, the Durbin-Watson statistic improves. It is better to use models other than least squares (AR1, ARIMA, lagged variable, GLS) for autocorrelated data.
🔑 Definition — Prais-Winsten estimator: A method for estimating regression models with AR(1) autocorrelated errors, transforming the data to remove autocorrelation.
⭐ Key Takeaways
The lecture shows the complete workflow for OLS regression in Stata: data exploration, running regress, generating predicted values and residuals, and diagnosing five core regression assumptions. You must remember that the robust option fixes standard errors for heteroskedasticity (VIF < 5 indicates no multicollinearity), the linktest and ovtest check for specification errors, and the Durbin-Watson test (via estat dwatson) detects autocorrelation, which can be remedied using the Prais-Winsten command. Transforming the dependent variable (e.g., inverse) can restore normality in residuals, and post-estimation commands like predict and histogram are essential for validation.
🧠 Quick Revision Questions
- What is the Stata syntax for running a linear regression of
priceonmpgandforeign? - How do you generate predicted values and residuals after a regression in Stata?
- What does the IM test (White test) check for, and how do you conduct it in Stata?
- What is the rule of thumb for detecting multicollinearity using VIF values?
- What is the Stata command to perform the Durbin-Watson test for autocorrelation, and how do you remedy autocorrelation if detected?
📘 Lecture 30 — Simultaneous Equation Models
📖 Overview: This lecture introduces simultaneous equation models, where variables can be both causes and effects, creating interdependence that violates OLS assumptions. It explains why OLS suffers from simultaneity bias in such systems and covers concepts like endogenous/exogenous variables, reduced form equations, and the identification problem that determines whether structural parameters can be recovered from reduced form coefficients.
🗂️ Topics Covered
This lecture covers the limitation of OLS with interdependent variables, introduces simultaneous equation models with multiple equations (market model, liquidity-profitability model, national income model), distinguishes between endogenous and exogenous variables, explains the identification problem (under-identified, exactly identified, over-identified), demonstrates the transformation to reduced form equations, and works through an example showing how structural parameters can be expressed in terms of reduced form coefficients using the exclusion principle.
📝 Lecture Summary
Simultaneous Equation Models
OLS deals with single equations where we have a response variable and some explanatory variables. However, variables in real life may be a cause as well as an effect. The interdependence of variables may give rise to simultaneity bias if OLS is used. For example, income is influenced by consumption level but consumption level itself depends on income levels.
To handle such relationships, we use simultaneous models with multiple equations where the dependent variable in one equation may be the explanatory variable in some other equation.
The Market Model:
Qd = α₀ + α₁P + α₂I + e₁
Qs = β₀ + β₁P + β₂T + e₂
Qd = Qs
The Liquidity and Profitability Model:
PROFITABILITY = α₀ + α₁LIQUIDITY + αᵢFᵢ + e₁
LIQUIDITY = β₀ + β₁PROFITABILITY + αᵢGᵢ + e₂
Where Fᵢ and Gᵢ are matrices of determinants of profitability and liquidity.
The National Income (Macroeconomic) Model:
Yₜ = Cₜ + Iₜ + Gₜ
Iₜ = α₀ + α₁Yₜ
Cₜ = β₀ + β₁Yₜ + e₂
Endogenous and Exogenous Variables
Consider the following model:
Y₁ = α₀ + α₁Y₂ + α₂X₁ + e₁
Y₂ = β₀ + β₁Y₁ + β₂X₂ + e₂
The number of unknowns is 4 and the number of equations is 2. To solve the model, the number of equations should be equal to the number of unknowns. Note that Y₁ and Y₂ cause each other. Let us assume that X₁ and X₂ are already given (their values determined externally from outside the model). These are called exogenous variables. The remaining variables whose values we seek by solving the model are called endogenous variables. Here X₁ and X₂ are exogenous and Y₁ and Y₂ are endogenous variables.
💡 Why this matters: In simultaneous models, the number of endogenous variables must equal the number of equations for the system to be solvable.
🔑 Definition — Endogenous variables: Variables whose values are determined within the model (Y₁, Y₂). 🔑 Definition — Exogenous variables: Variables whose values are determined outside the model (X₁, X₂).
📌 Example: In the market model (Qd = α₀ + α₁P + α₂I + e₁, Qs = β₀ + β₁P + β₂T + e₂, Qd = Qs):
- Endogenous variables: P (price) and Q (quantity), since they are determined by the model
- Exogenous variables: I (income) and T (technology), since they are given from outside
📌 Example: In a three-equation system:
Y₁ = α₀ + α₁Y₂ + α₂Y₃ + α₃X₁ + e₁
Y₂ = β₀ + β₁Y₁ + β₂Y₃ + β₃X₂ + e₂
Y₃ = γ₀ + γ₁Y₁ + γ₂Y₂ + γ₃X₃ + e₃
- We have three equations, so we must have three endogenous variables
- Y₁, Y₂, and Y₃ are endogenous
- All remaining variables X₁, X₂, and X₃ are exogenous
Identification Problem
An equation (not a model) can be Unidentified or Under-identified, Exactly identified or Over identified. If OLS cannot be applied, we need to transform the model to reduced form.
Reduced form equations: Equations that express endogenous variables as functions only of exogenous variables and disturbances. OLS can be applied to reduced-form equations (no endogenous variables on RHS). We need to solve and get reduced form equations for each endogenous variable. The number of endogenous variables in a model equals the number of reduced form equations.
For the model:
Y₁ = α₀ + α₁Y₂ + α₂X₁ + e₁
Y₂ = β₀ + β₁Y₁ + β₂X₂ + e₂
After transforming to reduced form:
Y₁ = π₁₀ + π₁₁X₁ + π₁₂X₂ + v₁
Y₂ = π₂₀ + π₂₁X₁ + π₂₂X₂ + v₂
βᵢ are called structural parameters. πᵢⱼ are called reduced form coefficients.
🔑 Definition — Unidentified or Under-identified: If we cannot express the structural parameters of an equation in terms of reduced form coefficients. 🔑 Definition — Exactly identified: If we CAN express the structural parameters of an equation in terms of reduced form coefficients in one way. 🔑 Definition — Over identified: If we CAN express the structural parameters of an equation in terms of reduced form coefficients in more than one way.
The Exclusion principle states: For an equation to be identified in a two-equation system, there should be at least one exogenous variable that is excluded from the equation (i.e., the variable does not exist in the equation but must be found on the RHS of the other equation).
Example — Transforming to Reduced Form and Checking Identification
Consider the model:
Y₁ = α₀ + α₁Y₂ + α₂X₁ + e₁ ... (1)
Y₂ = β₀ + β₁Y₁ + β₂X₂ + e₂ ... (2)
Substituting the value of Y₂ from equation (2) into equation (1) and solving for Y₁ gives:
Y₁ = (α₀ + α₁β₀)/(1 - α₁β₁) + (α₂/(1 - α₁β₁))X₁ + (α₁β₂/(1 - α₁β₁))X₂ + u₁
This can be written as:
Y₁ = π₁₀ + π₁₁X₁ + π₁₂X₂ + u₁ [Reduced form equation 1]
Now substituting this expression for Y₁ into equation (2) gives:
Y₂ = (β₀ + α₀β₁)/(1 - α₁β₁) + (β₁α₂/(1 - α₁β₁))X₁ + (β₂/(1 - α₁β₁))X₂ + u₂
This can be written as:
Y₂ = π₂₀ + π₂₁X₁ + π₂₂X₂ + u₂ [Reduced form equation 2]
The reduced form coefficients are:
π₁₀ = (α₀ + α₁β₀)/(1 - α₁β₁)
π₁₁ = α₂/(1 - α₁β₁)
π₁₂ = α₁β₂/(1 - α₁β₁)
π₂₀ = (β₀ + α₀β₁)/(1 - α₁β₁)
π₂₁ = β₁α₂/(1 - α₁β₁)
π₂₂ = β₂/(1 - α₁β₁)
Solving the above, we can express the structural parameters (αᵢ and βᵢ) in terms of reduced form coefficients:
β₁ = π₂₁/π₁₁
β₀ = π₂₀ - (π₂₁/π₁₁)π₁₀
β₂ = π₂₂ - (π₂₁/π₁₁)π₁₂
Since the structural parameters of equation (2) can be expressed in one way in terms of reduced form coefficients, Equation 2 is exactly identified.
Also:
α₁ = π₁₂/π₂₂
α₀ = π₁₀ - (π₁₂/π₂₂)π₂₀
α₂ = π₁₁ - (π₁₂/π₂₂)π₂₁
Since the structural parameters of equation (1) can be expressed in one way in terms of reduced form coefficients, Equation 1 is also exactly identified.
⭐ Key Takeaways
The most critical concept from this lecture is that simultaneous equation models arise when variables are interdependent, and applying OLS directly leads to simultaneity bias. You must distinguish between endogenous variables (determined within the model, equal in number to the equations) and exogenous variables (determined outside the model). To estimate such models, you transform them into reduced form equations where each endogenous variable is expressed solely as a function of exogenous variables and error terms. The identification problem determines whether you can recover the original structural parameters from the reduced form coefficients — equations can be under-identified (cannot recover), exactly identified (recover in one way), or over-identified (recover in multiple ways). The exclusion principle provides a simple check: in a two-equation system, each equation must exclude at least one exogenous variable present in the other equation to be identified.
🧠 Quick Revision Questions
- What is simultaneity bias, and why does OLS fail in simultaneous equation models?
- How do you identify which variables are endogenous and which are exogenous in a simultaneous equation system?
- What are reduced form equations, and how do they differ from structural equations?
- Explain the difference between under-identified, exactly identified, and over-identified equations.
- Using the market model (Qd = α₀ + α₁P + α₂I + e₁, Qs = β₀ + β₁P + β₂T + e₂, Qd = Qs), identify the endogenous and exogenous variables and explain why it is a simultaneous model.
📘 Lecture 31 — Simultaneous Equation Models-II
📖 Overview: This lecture continues the discussion of simultaneous equation models, focusing on the critical issue of identification. It demonstrates how to determine whether structural equations are under-identified, exactly identified, or over-identified using both algebraic derivation and the Order Condition, and explains which estimation method (ILS or 2SLS) is appropriate for each case.
🗂️ Topics Covered
The lecture begins with a detailed example of a market model (demand and supply) to show how to derive reduced form equations and check for exact identification. It then presents examples of under-identified and over-identified equations. Finally, it introduces the Order Condition as a quick rule for determining identification status and applies it to several examples with multiple endogenous variables.
📝 Lecture Summary
Identification of a Market Model
Consider the market model: 푄푑 = 훼0 + 훼1푃 + 훼2퐼 + 푒1 푄푠 = 훽0 + 훽1푃 + 훽2푇 + 푒2 푄푑 = 푄푠
Endogenous variables are Q and P. Exogenous variables are I and T.
Using the equilibrium condition 푄푑 = 푄푠: 훼0 + 훼1푃 + 훼2퐼 + 푒1 = 훽0 + 훽1푃 + 훽2푇 + 푒2
Solving for P: 푃 = (훽0 − 훼0)/(훼1 − 훽1) + (훽2/(훼1 − 훽1))푇 − (훼2/(훼1 − 훽1))퐼 + (푒2 − 푒1)/(훼1 − 훽1)
Labeling: 푃 = 휋10 + 휋11푇 + 휋12퐼 + 푣1
Where: 휋10 = (훽0 − 훼0)/(훼1 − 훽1), 휋11 = 훽2/(훼1 − 훽1), 휋12 = −훼2/(훼1 − 훽1)
Substituting into the demand equation: 푄 = 훼0 + 훼1(휋10 + 휋11푇 + 휋12퐼 + 푣1) + 훼2퐼 + 푒1 푄 = (훼0 + 훼1휋10) + 훼1휋11푇 + (훼1휋12 + 훼2)퐼 + (푒1 + 훼1푣1)
Labeling: 푄 = 휋20 + 휋21푇 + 휋22퐼 + 푣2
Where: 휋20 = 훼0 + 훼1휋10, 휋21 = 훼1휋11, 휋22 = 훼1휋12 + 훼2
All structural parameters can be expressed in terms of reduced form coefficients: 훽1 = 휋22/휋12, 훽0 = 휋20 − (휋22/휋12)휋10, 훽2 = 휋21 − (휋22/휋12)휋11 훼1 = 휋21/휋11, 훼2 = 휋22 − (휋21/휋11)휋12, 훼0 = 휋20 − (휋21/휋11)휋10
Hence both equations are exactly identified.
💡 Why this matters: When an equation is exactly identified, there is a unique way to recover the structural parameters from the reduced form coefficients, allowing for consistent estimation using Indirect Least Squares (ILS).
Example: Under-identified Equation
Consider the model: 푌1 = 훼0 + 훼1푌2 + 훼2푋1 + 푒1 푌2 = 훽0 + 훽1푌1 + 푒2
Exogenous variables: 푋1; Endogenous variables: 푌1 and 푌2
Substituting value of 푌2 in equation 1: 푌1 = (훼0 + 훼1훽0)/(1 − 훼1훽1) + (훼2/(1 − 훼1훽1))푋1 + (훼1푒2 + 푒1)/(1 − 훼1훽1)
Labeling: 푌1 = 휋10 + 휋11푋1 + 푣1
휋10 = (훼0 + 훼1훽0)/(1 − 훼1훽1), 휋11 = 훼2/(1 − 훼1훽1)
Substituting reduced form of 푌1 in equation 2: 푌2 = 훽0 + 훽1(휋10 + 휋11푋1 + 푣1) + 푒2 푌2 = (훽0 + 훽1휋10) + 훽1휋11푋1 + (훽1푣1 + 푒2)
Labeling: 푌2 = 휋20 + 휋21푋1 + 푣2
휋20 = 훽0 + 훽1휋10, 휋21 = 훽1휋11
We can solve for 훽1 and 훽0 but not for 훼푖. So only equation 2 is exactly identified. Equation 1 is unidentified.
🔑 Definition — Unidentified equation: An equation whose parameters cannot be estimated because there is not enough information in the reduced form to obtain meaningful estimates. The parameters of an unidentified equation have no interpretation.
Example: One Over-identified Equation
Consider the model: 푌1 = 훼0 + 훼1푌2 + 푒1 푌2 = 훽0 + 훽1푌1 + 훽2푋1 + 훽3푋2 + 푒2
Substituting the first equation in second and rearranging: 푌2 = (훽0 + 훽1훼0)/(1 − 훼1훽1) + (훽2/(1 − 훼1훽1))푋1 + (훽3/(1 − 훼1훽1))푋2 + (훽1푒1 + 푒2)/(1 − 훼1훽1)
Labeling: 푌2 = 휋20 + 휋21푋1 + 휋22푋2 + 푣2
Where: 휋20 = (훽0 + 훽1훼0)/(1 − 훼1훽1), 휋21 = 훽2/(1 − 훼1훽1), 휋22 = 훽3/(1 − 훼1훽1)
Substituting the reduced form for 푌2 in the first structural equation: 푌1 = 훼0 + 훼1(휋20 + 휋21푋1 + 휋22푋2 + 푣2) + 푒1 푌1 = (훼0 + 훼1휋20) + 훼1휋21푋1 + 훼1휋22푋2 + (훼1푣2 + 푒1) 푌1 = 휋10 + 휋11푋1 + 휋12푋2 + 푒1
Where: 휋10 = 훼0 + 훼1휋20, 휋11 = 훼1휋21, 휋12 = 훼1휋22
This means we can express 훼1 in terms of reduced form coefficients in two ways: 훼1 = 휋11/휋21 AND 훼1 = 휋12/휋22
Hence equation 1 is over-identified. Equation 2 is under-identified.
🔑 Definition — Over-identified equation: An equation where there are more than one way to express the structural parameters in terms of reduced form coefficients, providing redundant information.
📐 Formula — Appropriate estimation methods:
- If exactly identified → use ILS (Indirect Least Squares)
- If over-identified → use 2SLS (Two Stage Least Squares)
Order Condition for Identification Status
The Order Condition is a simple rule to determine identification status without deriving reduced forms. Compare two parameters:
- 푃1: Number of exogenous variables excluded from the equation = (total exogenous variables in model) − (exogenous variables in the equation)
- 푃2: Number of endogenous variables in the model minus 1
If 푃1 < 푃2, the equation is under-identified If 푃1 = 푃2, the equation is exactly identified If 푃1 > 푃2, the equation is over-identified
Example: 푌1 = 훼0 + 훼1푌2 + 훼2푋1 + 푒1 푌2 = 훽0 + 훽1푌1 + 훽2푋2 + 푒2
Equation 1: 푃1 = 1 (푋2 excluded), 푃2 = 2 − 1 = 1 → 푃1 = 푃2, exactly identified (apply ILS) Equation 2: 푃1 = 1 (푋1 excluded), 푃2 = 2 − 1 = 1 → 푃1 = 푃2, exactly identified (apply ILS)
Example (market model): 푄푑 = 훼0 + 훼1푃 + 훼2퐼 + 푒1 푄푠 = 훽0 + 훽1푃 + 훽2푇 + 푒2 푄푑 = 푄푠
Equation 1: 푃1 = 1 (푇 excluded), 푃2 = 2 − 1 = 1 → exactly identified (apply ILS) Equation 2: 푃1 = 1 (퐼 excluded), 푃2 = 2 − 1 = 1 → exactly identified (apply ILS)
Example: 푌1 = 훼0 + 훼1푌2 + 훼2푋1 + 푒1 푌2 = 훽0 + 훽1푌1 + 푒2
Equation 1: 푃1 = 0 (no exogenous variable excluded), 푃2 = 2 − 1 = 1 → 푃1 < 푃2, under-identified (no method) Equation 2: 푃1 = 1 (푋1 excluded), 푃2 = 2 − 1 = 1 → exactly identified (apply ILS)
Example: 푌1 = 훼0 + 훼1푌2 + 푒1 푌2 = 훽0 + 훽1푌1 + 훽2푋1 + 훽3푋2 + 푒2
Equation 1: 푃1 = 2 (both 푋1 and 푋2 excluded), 푃2 = 2 − 1 = 1 → 푃1 > 푃2, over-identified (apply 2SLS) Equation 2: 푃1 = 0 (no exogenous excluded), 푃2 = 2 − 1 = 1 → 푃1 < 푃2, under-identified (no method)
Example (three endogenous variables): 푌1 = 훼0 + 훼1푌2 + 훼2푌3 + 훽2푋1 + 푒1 푌2 = 훽0 + 훽1푌1 + 훽2푌3 + 훽3푋2 + 푒2 푌3 = 훾0 + 훾1푌1 + 훾2푌2 + 훾3푋3 + 푒3
Equation 1: 푃1 = 2 (푋2 and 푋3 excluded), 푃2 = 3 − 1 = 2 → 푃1 = 푃2, exactly identified (apply ILS) Equations 2 and 3 are also exactly identified.
⭐ Key Takeaways
The identification status of a structural equation is fundamental to choosing the correct estimation method. An equation is under-identified if it lacks enough excluded exogenous variables (푃1 < 푃2), making its parameters uninterpretable. It is exactly identified when the number of excluded exogenous variables equals the number of endogenous variables minus one (푃1 = 푃2), allowing the use of Indirect Least Squares (ILS). It is over-identified when more exogenous variables are excluded than needed (푃1 > 푃2), requiring Two Stage Least Squares (2SLS) for estimation. The Order Condition provides a quick way to determine identification status by simply counting and comparing these two parameters, without deriving reduced forms.
🧠 Quick Revision Questions
- What are the two parameters compared in the Order Condition, and how do you compute each?
- If an equation has 푃1 = 2 and 푃2 = 2, what is its identification status and which estimation method should be used?
- In the market model with demand (including I) and supply (including T), why are both equations exactly identified?
- What does it mean when an over-identified equation has two different ways to compute the same structural parameter (e.g., 훼1 = 휋11/휋21 and 훼1 = 휋12/휋22)?
- Why can no estimation method be applied to an under-identified equation?
📘 Lecture 32 — Indirect Least Square (ILS)
📖 Overview: This lecture introduces the Indirect Least Squares (ILS) method, a technique used to obtain consistent estimates of structural parameters in simultaneous equation models when an equation is exactly identified. It contrasts ILS with direct OLS estimation, which suffers from simultaneity bias, and demonstrates the complete ILS procedure through step-by-step examples and Stata implementation.
🗂️ Topics Covered
The lecture covers the concept and steps of Indirect Least Squares (ILS), including the order condition for identification, derivation of reduced form equations, and expression of structural parameters in terms of reduced form coefficients. Two detailed examples are worked through with actual data: a two-equation macroeconomic model and a demand-supply system. The lecture also discusses exclusion restrictions for identification, the role of shifters (technology and income), and the Stata implementation of ILS using the reg3 command for 2SLS.
📝 Lecture Summary
What is Indirect Least Square (ILS)?
Indirect least square may be applied when an equation is exactly identified. ILS will provide consistent estimates of the structural parameters. Applying OLS (Ordinary Least Squares) to individual equations of a simultaneous equation model does not provide consistent results due to simultaneity bias, where endogenous variables are correlated with error terms.
Steps of ILS
- Apply order condition to check identification status
- Find the reduced form equations
- Express the structural parameters in terms of reduced form coefficients
- Estimate the reduced form coefficients by OLS
- Calculate the structural parameters
Example 1: Two-Equation System
Consider the structural equations: [ Y_1 = \alpha_0 + \alpha_1 Y_2 + \alpha_2 X_1 + e_1 ] [ Y_2 = \beta_0 + \beta_1 Y_1 + \beta_2 X_2 + e_2 ]
Applying the order condition shows that both equations are exactly identified.
The reduced form equations are: [ Y_1 = \pi_{10} + \pi_{11} X_1 + \pi_{12} X_2 + u_1 ] [ Y_2 = \pi_{20} + \pi_{21} X_1 + \pi_{22} X_2 + u_1 ]
Expressing structural parameters in terms of reduced form coefficients: [ \beta_1 = \frac{\pi_{21}}{\pi_{11}}, \quad \beta_0 = \pi_{20} - \frac{\pi_{21}}{\pi_{11}} \pi_{10}, \quad \beta_2 = \pi_{22} - \frac{\pi_{21}}{\pi_{11}} \pi_{12} ] [ \alpha_1 = \frac{\pi_{12}}{\pi_{22}}, \quad \alpha_0 = \pi_{10} - \frac{\pi_{12}}{\pi_{22}} \pi_{20}, \quad \alpha_2 = \pi_{11} - \frac{\pi_{12}}{\pi_{22}} \pi_{21} ]
Data (ILS.xlsx):
| Y₁ | Y₂ | X₁ | X₂ |
|---|---|---|---|
| 25 | 0.8 | 10 | 12 |
| 25 | 0.9 | 8 | 11 |
| 27 | 0.8 | 8 | 12 |
| 29 | 1.2 | 7 | 11 |
| 32 | 1.2 | 6 | 9 |
| 32 | 1.6 | 3 | 8 |
| 33 | 1.9 | 4 | 8 |
| 36 | 2.1 | 5 | 7 |
| 40 | 2.0 | 4 | 5 |
| 49 | 2.0 | 2 | 5 |
OLS estimation of reduced form equations gives: [ Y_1 = 54.96 - 0.245 X_1 - 2.359 X_2 ] [ Y_2 = 3.011 - 0.039 X_1 - 0.152 X_2 ]
Reduced form coefficients: [ \pi_{10} = 54.96086, \quad \pi_{11} = -0.24518, \quad \pi_{12} = -2.35947 ] [ \pi_{20} = 3.010546, \quad \pi_{21} = -0.03949, \quad \pi_{22} = -0.15175 ]
Indirect estimation of structural parameters: [ \alpha_{0-ILS} = 8.152606, \quad \alpha_{1-ILS} = 15.54809, \quad \alpha_{2-ILS} = 0.368888 ] [ \beta_{0-ILS} = -5.8429, \quad \beta_{1-ILS} = 0.161086, \quad \beta_{2-ILS} = 0.228326 ]
The estimated structural equations are: [ Y_1 = 8.15 + 15.55 Y_2 + 0.369 X_1 ] [ Y_2 = -5.84 + 0.161 Y_1 + 0.228 X_2 ]
💡 Why this matters: If we would have estimated the structural equations individually by OLS, we would have gotten different and inconsistent results due to simultaneity bias.
Example 2: Demand and Supply System
Consider the demand and supply equations: [ Q^d = \alpha_0 + \alpha_1 P + \alpha_2 I + e_1 ] [ Q^s = \beta_0 + \beta_1 P + \beta_2 T + e_2 ] [ Q^d = Q^s ]
Applying the order condition shows both equations are exactly identified.
Reduced form equations: [ P = \pi_{10} + \pi_{11} T + \pi_{12} I + v_1 ] [ Q = \pi_{20} + \pi_{21} T + \pi_{22} I + v_2 ]
Structural parameters expressed in terms of reduced form coefficients: [ \beta_1 = \frac{\pi_{22}}{\pi_{12}}, \quad \beta_0 = \pi_{20} - \frac{\pi_{22}}{\pi_{12}} \pi_{10}, \quad \beta_2 = \pi_{21} - \frac{\pi_{22}}{\pi_{12}} \pi_{11} ] [ \alpha_1 = \frac{\pi_{21}}{\pi_{11}}, \quad \alpha_2 = \pi_{22} - \frac{\pi_{21}}{\pi_{11}} \pi_{12}, \quad \alpha_0 = \pi_{20} - \frac{\pi_{21}}{\pi_{11}} \pi_{10} ]
Data (ILS.xlsx):
| Quantity (Q) | Price (P) | Income (I) | Technology (T) |
|---|---|---|---|
| 5 | 3 | 5 | 0.2 |
| 6 | 5 | 10 | 0.5 |
| 7 | 2 | 6 | 0.5 |
| 4 | 6 | 7 | 0.2 |
| 6 | 10 | 15 | 0.2 |
| 9 | 5 | 8 | 0.5 |
| 11 | 6 | 10 | 0.9 |
| 7 | 6 | 8 | 0.5 |
| 6 | 12 | 12 | 0.2 |
| 12 | 12 | 16 | 0.9 |
OLS estimation of reduced form equations: [ P = -0.82 - 2.62 T + 0.9 I ] [ Q = 2.12 + 8.2 T + 0.15 I ]
Reduced form coefficients: [ \pi_{10} = -0.82, \quad \pi_{11} = -2.62, \quad \pi_{12} = 0.9 ] [ \pi_{20} = 2.12, \quad \pi_{21} = 8.2, \quad \pi_{22} = 0.15 ]
Indirect estimation of structural parameters: [ \alpha_{0-ILS} = -0.45087, \quad \alpha_{1-ILS} = -3.12665, \quad \alpha_{2-ILS} = 2.958705 ] [ \beta_{0-ILS} = 2.250948, \quad \beta_{1-ILS} = 0.161495, \quad \beta_{2-ILS} = 8.623996 ]
The estimated structural equations are: [ Q^d = -0.45 - 3.13 P + 2.96 I ] [ Q^s = 2.25 + 0.16 P + 8.62 T ]
💡 Why this matters: If we would have estimated the structural equations individually by OLS, we would have gotten different and inconsistent results.
ILS using Stata
The reg3 command can be used in Stata. reg3 is a command for 3SLS (the option 2sls can be used). For exactly identified equations, 2SLS results are identical to ILS.
Example II can be done as follows:
reg3 q p i, exog(i t) endog(q p) 2sls
reg3 q p t, exog(i t) endog(q p) 2sls
From the interface: Statistics → Linear Models → Multiple equation models → Three stage least square
🔑 Key insight: In a two-equation system, at least one variable must be excluded from an equation to make it identified.
Understanding Identification: Exclusion Restriction
Consider two points on the same demand curve. Two points on the demand curve show different supply curves. The supply curve shifts through 'shift factors' or supply shifters. Technology is a supply shifter.
The two points are on the same demand curve. Technology must not appear in the demand equation because if it does, it will shift the demand as well. To have two points on the same demand curve, we need an exogenous variable that does not shift the demand curve but only the supply curve.
Now consider two points on the same supply curve. Two points on the supply curve show different demand curves. The demand curve shifts through 'shift factors' or demand shifters. Income level is a demand shifter.
To show both points (different demand curves), income level must appear in the demand equation. It must not appear in the supply equation because if it does, it will shift the supply as well. To have two points on the same supply curve, we need an exogenous variable that does not shift the supply curve but only the demand curve.
Notes and Assumptions on ILS
We can directly write the reduced form equations without solving the model. We need to solve the model to derive the structural parameters from the reduced form coefficients. 2SLS also can be applied to exactly identified equations with the same results as ILS. ILS and 2SLS provide the same results when 2SLS is applied to a single equation. ILS and 3SLS may provide the same results when applied to a complete system. (Park, Canadian Journal of Statistics 01/1974)
Assumptions of ILS:
- Equations must be exactly identified
- Error terms in all reduced form equations must satisfy all usual assumptions of OLS estimation
- No multicollinearity in exogenous variables
- Sample size not very small (ILS is biased for small samples)
⭐ Key Takeaways
Indirect Least Squares (ILS) is the appropriate estimation method for exactly identified structural equations in simultaneous equation models, providing consistent estimates that direct OLS cannot achieve due to simultaneity bias. The procedure involves estimating reduced form equations by OLS and then solving back for structural parameters using the mathematical relationships between reduced form coefficients and structural parameters. The exclusion restriction is fundamental for identification: to trace a demand curve, we need a supply shifter (like technology) that is excluded from the demand equation, and to trace a supply curve, we need a demand shifter (like income) excluded from the supply equation. ILS assumes exactly identified equations, classical OLS assumptions for each reduced form equation, no multicollinearity among exogenous variables, and sufficiently large sample sizes.
🧠 Quick Revision Questions
- Why can't we simply apply OLS to each structural equation in a simultaneous equation model, and what problem does ILS solve?
- What are the five steps required to implement the ILS procedure?
- How does the exclusion restriction help identify demand and supply curves, and what specific variables serve as shifters in the examples?
- What is the relationship between ILS and 2SLS results for exactly identified equations?
- What are the four key assumptions that must be satisfied for ILS to provide valid estimates?
📘 Lecture 33 — Two Stage Least Square
📖 Overview: This lecture explains the Two Stage Least Square (2SLS) method for estimating parameters of over-identified equations in simultaneous equation models. It demonstrates both stages of the procedure with two detailed numerical examples, contrasts 2SLS estimates with inappropriate OLS estimates, and shows how to implement the method using Stata.
🗂️ Topics Covered
The lecture covers the two-stage procedure for 2SLS estimation, beginning with deriving reduced forms for endogenous variables on the right-hand side of the over-identified equation and estimating them using OLS in Stage I. Stage II involves replacing the endogenous variable with its trend values from the reduced form and re-estimating using OLS. Two worked examples (a general two-equation model and a supply-demand model) are presented with numerical data. The lecture also explains the order condition for over-identification, shows the calculation of trend values, compares 2SLS estimates with direct OLS estimates, and ends with Stata commands using reg3 and ivregress.
📝 Lecture Summary
Two Stage Least Square
We can use 2SLS to estimate the parameters of over-identified equations.
Stage I: Derive or write the reduced forms for all endogenous variables on the RHS of the over-identified equation and estimate them using OLS.
Stage II: Find the trend value of the above estimated reduced form equations, replace with the variables in the over-identified equation, and estimate it using OLS.
Consider the model: 푌₁ = 훼₀ + 훼₁푌₂ + 푒₁ 푌₂ = 훽₀ + 훽₁푌₁ + 훽₂푋₁ + 훽₃푋₂ + 푒₂
Stage I: The first equation is over-identified (verified using the order condition). Since 푌₂ is the endogenous variable on the RHS of the first (over-identified) equation, we need to estimate the reduced form for 푌₂.
Stage II: Replace 푌₂ with 푌̂₂ (from the reduced form) and estimate it using OLS.
Detailed Procedure with Example 1
Let us do it in detail: 푌₁ = 훼₀ + 훼₁푌₂ + 푒₁ 푌₂ = 훽₀ + 훽₁푌₁ + 훽₂푋₁ + 훽₃푋₂ + 푒₂
Order Condition: Equation 1 Number of exogenous variables excluded from the equation is 2, which is greater than the number of endogenous variables in the model minus one (which gives 1). So equation 1 is over-identified. ILS cannot be used.
Stage 1
- We need the reduced form for the endogenous variable on the RHS of equation 1.
- 푌₂ is the variable.
Reduced form equations contain only exogenous variables, and they contain all the exogenous variables of the model. 푌₂ = 휋₁₀ + 휋₁₁푋₁ + 휋₁₂푋₂ + 푣₁
For 2SLS, we do not need to know what the πᵢ are equivalent to.
Now consider a small data set (2SLS.xlsx) to estimate: 푌₂ = 휋₁₀ + 휋₁₁푋₁ + 휋₁₂푋₂ + 푣₁
The estimates are: 푌₂ = 3.011 – 0.039 푋₁ – 0.152 푋₂
This gives the trend values for 푌₂: 0.794564, 1.025306, 0.873553, 1.0648, 1.407801, 1.678038, 1.638543, 1.750802, 2.093803, 2.172792
Stage I is complete now.
Stage II In Stage II, we replace the variable Y₂ in the original over-identified equation with the trend values from the reduced form of Y₂ and run the regression.
The original (over-identified) equation was: 푌₁ = 훼₀ + 훼₁푌₂ + 푒₁
After replacing Y₂ with the estimated Y₂: 푌₁ = 훼₀ + 훼₁푌̂₂ + 푒₁
Estimating this gives: 푌₁ = 12.81 + 13.785 푌̂₂
12.81 and 13.785 are the 2SLS estimates of 훼₀₋₂SLS and 훼₁₋₂SLS. If we had directly regressed 푌₁ on 푌₂, we would have got 16.03 and 11.6 as 훼₀₋OLS and 훼₁₋OLS (not appropriate estimates).
Example 2: Supply-Demand Model
Consider the model: 푄ᵈ = 훼₀ + 훼₁푃 + 푒₁ 푄ˢ = 훽₀ + 훽₁푃 + 훽₂퐶 + 훽₃푇 + 푒₂ 푄ᵈ = 푄ˢ
Where: 푃 = Price, 푄 = Quantity (demanded or supplied) 퐶 = Cost of production, 푇 = The level of technology
- 2SLS is needed for the first equation.
- Stage I: The first equation is over-identified. Since 푃 is the endogenous variable on the RHS of the first (over-identified) equation, we need to estimate the reduced form for 푃.
- Stage II: Replace 푃 with 푃̂ (from the reduced form) in the demand equation and estimate using OLS.
Order Condition: Demand equation Number of exogenous variables excluded from the equation is 2, which is greater than the number of endogenous variables in the model minus one (which gives 1). So the demand equation is over-identified. ILS cannot be used.
Stage 1
- We need the reduced form for the endogenous variable on the RHS of the demand equation.
- Q and P are endogenous; C and T are exogenous variables.
- 푃 is the variable for which the reduced form is needed.
Reduced form equations contain only exogenous variables and contain all the exogenous variables of the model. 푃 = 휋₁₀ + 휋₁₁퐶 + 휋₁₂푇 + 푣₁
Using the data set, the estimates are: 푃 = 0.868 + 0.548 퐶 + 1.3683 푇
This gives the trend values for 푃: 6.618038, 7.028532, 6.480933, 7.713237, 6.070439, 5.933333, 5.933059, 6.480933, 6.070439, 8.671056
Stage I is complete now.
Stage II In Stage II, we replace the variable P in the original over-identified equation with the trend values from the reduced form of P and run the regression.
The original (over-identified) equation was: 푄ᵈ = 훼₀ + 훼₁푃 + 푒₁
After replacing P with the estimated P: 푄 = 훼₀ + 훼₁푃̂ + 푒₁
Estimating this gives: 푄 = 4.1735 + 0.4667 푃̂
4.1735 and 0.4667 are the 2SLS estimates of 훼₀₋₂SLS and 훼₁₋₂SLS. If we had directly regressed 푄 on 푃, we would have got 5.906 and 0.20799 as 훼₀₋OLS and 훼₁₋OLS (not appropriate estimates).
Using Stata for Two Stage Least Square (2SLS)
Using reg3 (preferred) On the Menu: Statistics > Endogenous covariates > Three-stage least squares. In the window, after providing required information, check the option 2SLS.
For Example 1, in the command window type:
reg3 (y1 y2) (y2 x1 x2), 2sls
For Example 2, in the command window type:
reg3 (q p) (p c t), 2sls
Using ivregress In some cases ivregress can be used, but prefer reg3.
For Example 1, in the command window type:
ivregress 2sls y1 (y2= x1 x2)
The syntax is: ivregress 2sls dependent-variable (instrumented-variable=instruments)
We can use the option first to see the Stage I results:
ivregress 2sls y1 (y2= x1 x2), first
For Example 2, in the command window type:
ivregress 2sls q (p= c t)
ivregress 2sls q (p= c t), first
💡 Why this matters: Direct OLS estimation of an over-identified equation produces biased and inconsistent estimates because the endogenous variable on the RHS is correlated with the error term. 2SLS solves this by using instruments (excluded exogenous variables) to generate predicted values that are uncorrelated with the error, yielding consistent estimates.
🔑 Definition — Over-identified equation: An equation in a simultaneous equation model where the number of exogenous variables excluded from the equation is greater than the number of endogenous variables in the model minus one. ILS cannot be used for such equations.
🔑 Definition — Reduced form equation: An equation that expresses an endogenous variable solely as a function of all exogenous variables in the system. It contains no other endogenous variables on the RHS.
📐 Formula — 2SLS Stage I: For an over-identified equation with endogenous Y₂ on RHS, estimate: 푌₂ = 휋₁₀ + 휋₁₁푋₁ + 휋₁₂푋₂ + 푣₁ → Compute fitted values 푌̂₂.
📐 Formula — 2SLS Stage II: Replace Y₂ with 푌̂₂ and estimate: 푌₁ = 훼₀ + 훼₁푌̂₂ + 푒₁ → Obtain consistent 2SLS estimates of 훼₀ and 훼₁.
📌 Example (from lecture): In the first data set, direct OLS gave 푌₁ = 16.03 + 11.6 푌₂, but the correct 2SLS estimates are 푌₁ = 12.81 + 13.785 푌̂₂. In the supply-demand example, direct OLS gave 푄 = 5.906 + 0.20799 푃, but correct 2SLS estimates are 푄 = 4.1735 + 0.4667 푃̂.
⭐ Key Takeaways
For any over-identified equation in a simultaneous equation system, 2SLS is the appropriate estimation method because ILS is not applicable. The method proceeds in two clear stages: first, estimate the reduced form for each endogenous variable appearing on the RHS of the over-identified equation using all exogenous variables as regressors; second, replace the actual endogenous variable with its fitted (trend) values from the reduced form and estimate the original equation using OLS to obtain consistent parameter estimates. Direct OLS estimation of the original equation gives biased and inconsistent results because the endogenous regressor is correlated with the error term. The order condition must be checked first: if the number of excluded exogenous variables exceeds (number of endogenous variables minus one), the equation is over-identified and 2SLS is required.
🧠 Quick Revision Questions
- Why can ILS not be used for an over-identified equation, and which method should be used instead?
- What is the key difference in the Stage I regression between 2SLS and a simple reduced form estimation?
- In the first example, what are the 2SLS estimates of 훼₀ and 훼₁, and how do they compare to the direct OLS estimates?
- What does the
firstoption do when used with theivregresscommand in Stata? - For the supply-demand model, identify the instruments used for the demand equation and explain why they are valid.
📘 Lecture 34 — 2SLS & 3SLS Models
📖 Overview: This lecture explains why OLS fails when a system contains multiple endogenous variables, and introduces Two-Stage Least Squares (2SLS) and Three-Stage Least Squares (3SLS) as solutions. It covers the mathematical proof that 2SLS equals Indirect Least Squares (ILS) for exactly identified equations, a numerical example, and the motivation for using 3SLS to improve efficiency by accounting for cross-equation error correlations.
🗂️ Topics Covered
The lecture begins by explaining why 2SLS is needed when there are multiple endogenous variables in a system of equations, as OLS becomes biased. It introduces the Durban and Wu-Hausman tests for endogeneity. It then presents a mathematical proof showing 2SLS equals ILS for exactly identified equations, followed by a numerical example using Excel. The lecture concludes by introducing 3SLS as an extension of 2SLS that accounts for correlations between error terms of different equations, and demonstrates its implementation in Stata.
📝 Lecture Summary
Why to use 2SLS?
OLS has only one endogenous variable (the dependent variable). When we have a system of equations, there may be several endogenous variables. When a variable is endogenous, it may be correlated with the disturbance term, leading to biased OLS estimates. The goal of 2SLS is to find a proxy for the endogenous variable that is not correlated with the error term (e). This proxy is denoted as ( \hat{P} ). ( \hat{P} ) should not be correlated with ( e_1 ).
Testing Endogeneity: Durban and Wu-Hausman Tests
After using the ivregress command in Stata, the post-estimation command to test for endogeneity is:
estat endogeneity
If p-values are less than 5%, we can reject the null hypothesis (( H_0 )) of exogenous regressors and conclude that the variables can be used as endogenous variables.
💡 Why this matters: This test formally confirms whether 2SLS is necessary or if OLS would have been unbiased.
Proof: 2SLS == ILS for exactly identified equations
Consider the model: [ Y_1 = \alpha_0 + \alpha_1 Y_2 + e_1 ] [ Y_2 = \beta_0 + \beta_1 Y_1 + \beta_2 X_1 + e_2 ]
The reduced form equations are: [ Y_1 = \pi_{10} + \pi_{11} X_1 + u_1 ] [ Y_2 = \pi_{20} + \pi_{21} X_1 + u_2 ]
Where: [ \pi_{11} = \frac{\alpha_1 \beta_2}{(1 - \alpha_1 \beta_1)}, \quad \pi_{21} = \frac{\beta_2}{(1 - \alpha_1 \beta_1)} ]
🔑 Definition — ILS (Indirect Least Squares): A method where the structural parameters are derived from the reduced form parameters estimated by OLS.
Applying ILS: [ \alpha_{1_{ILS}} = \frac{\pi_{11}}{\pi_{21}} ]
We estimate the two reduced forms by OLS: [ \hat{\pi}{11{OLS}} = \frac{\sum x_1 y_1}{\sum x_1^2}, \quad \hat{\pi}{21{OLS}} = \frac{\sum x_1 y_2}{\sum x_1^2} ]
Applying 2SLS: We estimate ( \hat{Y}2 ) and replace it in the first equation. Since ( Y_2 = \pi{20} + \pi_{21} X_1 + u_2 ), we have ( \hat{Y}2 = \hat{\pi}{21} X_1 ).
Replacing in the original equation: [ Y_1 = \alpha_0 + \alpha_1 \hat{Y}_2 + e_1 ]
The 2SLS estimator is: [ \alpha_{1_{2SLS}} = \frac{\sum Y_1 \hat{Y}2}{\sum \hat{Y}2^2} = \frac{\sum Y_1 \hat{\pi}{21} X_1}{\sum (\hat{\pi}{21} X_1)^2} = \frac{\hat{\pi}{21} \sum X_1 Y_1}{(\hat{\pi}{21})^2 \sum X_1^2} = \frac{1}{\hat{\pi}_{21}} \frac{\sum X_1 Y_1}{\sum X_1^2} ]
📐 Formula: [ \alpha_{1_{2SLS}} = \frac{\sum X_1 Y_1}{\sum X_1^2} \cdot \frac{1}{\hat{\pi}{21}} = \frac{\frac{\sum X_1 Y_1}{\sum X_1^2}}{\hat{\pi}{21}} = \frac{\hat{\pi}{11}}{\hat{\pi}{21}} = \alpha_{1_{ILS}} ]
Therefore, ( \alpha_{1_{2SLS}} = \alpha_{1_{ILS}} ). ILS and 2SLS provide identical results when applied to exactly identified equations.
Numerical Example
Consider the same model. We can estimate it using data from ILS-2SLS.xlsx.
| ( Y_1 ) | ( Y_2 ) | ( X_1 ) |
|---|---|---|
| 25 | 0.8 | 10 |
| 25 | 0.9 | 8 |
| 27 | 0.8 | 8 |
| 29 | 1.2 | 7 |
| 32 | 1.2 | 6 |
| 32 | 1.6 | 3 |
| 33 | 1.9 | 4 |
| 36 | 2.1 | 5 |
| 40 | 2.0 | 4 |
| 49 | 2.0 | 2 |
Using the slope function in Excel: [ \hat{\pi}{11} = -2.45439, \quad \hat{\pi}{21} = -0.18158 ]
[ \alpha_{1_{ILS}} = \frac{\hat{\pi}{11}}{\hat{\pi}{21}} = \frac{-2.45439}{-0.18158} = 13.51659 ]
Now 2SLS: Stage I: Regress ( Y_2 ) on ( X_1 ) to get ( \hat{Y}_2 ):
| ( \hat{Y}_2 ) |
|---|
| 0.669191 |
| 1.032358 |
| 1.032358 |
| 1.213941 |
| 1.395525 |
| 1.940275 |
| 1.758692 |
| 1.577108 |
| 1.758692 |
| 2.121859 |
Stage II: Replace ( Y_2 ) with ( \hat{Y}2 ) in the first equation and estimate: [ \alpha{1_{2SLS}} = 13.51659 = \alpha_{1_{ILS}} ]
📌 Example: This confirms that ILS and 2SLS provide identical results for exactly identified equations.
Three Stage Least Square (3SLS)
Background:
- OLS: Inconsistent for systems with simultaneous equations.
- 2SLS: "Cleans" the endogenous regressors.
- Regress endogenous variables against all predetermined variables of the system (reduced form). This gives "theoretical values".
- Use OLS for theoretical values, replacing the original values.
Possible Problem with 2SLS:
- 2SLS focuses on a single equation in the system.
- Correlations between error terms of various equations are ignored.
- This may give inefficient estimates.
Solution: Use 3SLS (Zellner & Theil, 1962):
- After 2SLS, we add a third stage to account for correlations of error terms.
- 3SLS uses the results of 2SLS to estimate all coefficients of the system simultaneously.
- 3SLS is more efficient compared to 2SLS.
- 3SLS is better when the correlation of error terms is not small.
3SLS using Stata
Syntax:
reg3 (depvar1 varlist1) (depvar2 varlist2) ...... (depvarN varlistN) [if] [in] [weight]
Menu: Statistics > Endogenous Covariates > Three Stage Least Square
Example using klein dataset:
webuse klein
describe
EQ1: consump wagepriv wagegovt
EQ2: wagepriv consump govt capital1
Important options:
noconst: omits constant term for an equation if specified in an equation; omits constant term from instrument list (stage I) if specified overall.ireg3: iterates over the estimated disturbance covariance matrix and parameter estimates until the parameter estimates converge.sure: performs a seemingly unrelated regression estimation of the system - even if dependent variables from some equations appear as regressors in other equations.2sls: performs equation-by-equation two stage least squares on the full system of equations.first: requests display of first stage regression.corr: specifies the assumed form of the correlation structure of the equation disturbances; rarely requested.small: small sample statistics are also computed.3sls: performs three stage least square; this is the default.
⭐ Key Takeaways
The core insight is that when multiple endogenous variables exist in a system of equations, OLS is biased. 2SLS solves this by finding a proxy (the predicted value from a first-stage regression) that is uncorrelated with the error term. A formal proof demonstrates that for exactly identified equations, 2SLS and ILS yield identical estimates. However, 2SLS ignores cross-equation error correlations, leading to inefficient estimates. Three-Stage Least Squares (3SLS) addresses this by adding a third stage that accounts for these correlations, making it more efficient, especially when error terms are highly correlated. The Durban-Wu-Hausman test should always be used to confirm the presence of endogeneity.
🧠 Quick Revision Questions
- Why is OLS biased when estimating a system of simultaneous equations with multiple endogenous variables?
- What is the fundamental goal of the first stage in 2SLS, and what property must the resulting proxy variable have?
- Mathematically, prove that ( \alpha_{1_{2SLS}} = \alpha_{1_{ILS}} ) for an exactly identified equation.
- What is the key limitation of 2SLS that 3SLS aims to overcome, and how does 3SLS achieve this?
- What Stata post-estimation command is used to test for endogeneity after running
ivregress, and what does a p-value less than 5% indicate?
📘 Lecture 35 — Panel Data Methods
📖 Overview: This lecture introduces panel data, a type of econometric data that tracks the same cross-sectional entities over time. It explains the benefits, drawbacks, and key estimation models for panel data, including pooled regression, fixed effects, and random effects models.
🗂️ Topics Covered
The lecture covers the types of econometric data including time series, cross-sectional, pooled, and panel data, with detailed definitions and examples. It discusses panel data types (short/long, balanced/unbalanced, fixed/rotating), benefits and drawbacks, the rationale for using panel data due to unobserved heterogeneity, and estimation models including pooled regression, Least Square Dummy Variable (LSDV) models, and the error component model distinguishing between fixed and random effects.
📝 Lecture Summary
Types of Econometric Data
Econometric data can be classified into several types. Time Series Data involves observations at different points in time. Cross Sectional Data involves observations of different entities at the same point in time. Pooled Data is a mixture of time series and cross-sectional data. Panel Data (also called longitudinal data or repeated cross sections) is a specific type of data where the same cross-sectional entities are observed over time.
🔑 Definition — Pooled Data: Randomly sampled cross sections of individuals at different points in time.
📌 Example of Pooled Data:
| Respondent | Year | Income (Rs.) | Expenditure (Rs.) |
|---|---|---|---|
| Ali | 2012 | 12000 | 9500 |
| Arif | 2012 | 15000 | 11500 |
| Sakina | 2012 | 11500 | 9000 |
| Ali | 2013 | 12500 | 10000 |
| Jameel | 2013 | 11000 | . |
| Fatima | 2013 | 14000 | 12500 |
| Baqir | 2013 | 9500 | 8500 |
In pooled data, individuals may or may not be repeated, there may be different numbers of observations in different time periods, and there may be missing values.
Examples of pooled data include Women's Fertility over time, Population Survey, Labor Force Survey, Marketing Surveys, and Consumer Surveys.
🔑 Definition — Panel Data: Observe cross sections of the same individuals at different points in time.
Examples of panel data include: • Panel Survey of Income Dynamics (PSID) • British Household Panel Survey (BHPS) • US Time Use Surveys • French Time Use Surveys • German Socio-Economic Panel • National Longitudinal Surveys (NLS)
Panel data is also a pooled data set, but not all pooled data should be called panels.
📌 Panel Dataset Example:
| Country | Year | Y | X |
|---|---|---|---|
| 1 | 2012 | 6 | 9 |
| 1 | 2012 | 3 | 8 |
| 1 | 2012 | 5 | 11 |
| 2 | 2013 | 9 | 12 |
| 2 | 2013 | 5 | 7 |
| 2 | 2013 | 6 | 14 |
| 3 | 2014 | 11 | 14 |
| 3 | 2014 | 6 | 5 |
| 3 | 2014 | 8 | 16 |
Panel data shows the behavior of individual entities across time. The same set of individuals are normally observed, though there may be missing values.
Types of Panel Data
Panel data can be classified into several types.
Short and Long Panel: A Short Panel has many entities but few time periods. A Long Panel has many time periods.
Balanced and Unbalanced Panel: A Balanced Panel has all entities with measurements in all time periods (number of observations = nT). An Unbalanced Panel has missing observations for some entities in some time periods.
Fixed and Rotating Panel: A Fixed Panel has individuals that remain the same. A Rotating Panel (also called Pseudo Panels) has individuals that change over time.
Compact Panel: A Compact Panel has consecutive time periods.
Panel Data Benefits
Panel data offers several advantages:
- More degrees of freedom (nT)
- Captures more complexities (blends both cross-sectional and time series behavior)
- Better forecasts
- We can study heterogeneity and avoid omitted variable bias
Panel Data Drawbacks
Panel data also has drawbacks:
- Data collection issues
- Sampling design and coverage issues
- No response cases in micro panels
- Cross-country correlation in case of macro panels (e.g., location or spatial correlation, gravity models)
- Attrition: dropping out of individuals leads to an unbalanced and/or uncompact panel
Rationale for Using Panel Data
The main rationale for using panel data is Unobserved Heterogeneity. Many individual characteristics are not observed; examples include risk-taking behavior and ability. These vary across individuals and are called unobserved heterogeneity. If they influence the response variable and are correlated to regressors, OLS results will be biased.
💡 Why this matters: Unobserved heterogeneity is a major source of bias in cross-sectional regressions. Panel data allows us to control for these unobserved, time-invariant characteristics.
Examples of Unobserved Heterogeneity: • Returns to Education: Ability is not observed; returns may be influenced due to ability • Discrimination: Race, Gender, Religion • Unobserved characteristics of groups: Attitude to risk, Social behavior, Working habits • Macro Panels (e.g., country GDP): Countries have some unobserved characteristics
Pooled Regression
If we ignore the panel structure of the model and just run a regression, it is called a pooled regression or regression on pooled data. We have to assume that the error is ( e_{it} \sim N(0, \sigma^2) ), which may not be the case. We can pool the data with or without constraints on the disturbance term. We can use the Chow test (discussed with Stata) to test whether pooling is appropriate.
Least Square Dummy Variable Model
Dummy Variables can be used for different individual or time entities or both. Regression could be run using the dummy variables on the RHS of the regression equation. We can capture different intercepts for different groups. Problems include lack of degrees of freedom or the dummy variable trap.
Error Component: One Way and Two Way
Consider the model with ( e_{it} = \mu_i + u_{it} ).
Fixed Effect: When we assume ( \mu_i ) to be constant (for one individual, different for different individuals).
Random Effect: When we assume ( \mu_i ) is drawn independently from some probability distribution.
⭐ Key Takeaways
Panel data tracks the same entities over time, allowing researchers to control for unobserved heterogeneity that would bias OLS in cross-sectional regressions. The key advantage is the ability to study individual-specific characteristics that are time-invariant and unobserved, such as ability or risk attitude. Panel data estimation models include pooled regression (which ignores the panel structure), Least Square Dummy Variable (LSDV) models (which use dummy variables for entities), and error component models. The error component model splits the error term into an individual-specific component (( \mu_i )) and an idiosyncratic component (( u_{it} )), with fixed effects treating ( \mu_i ) as constant and random effects treating it as randomly drawn from a distribution.
🧠 Quick Revision Questions
- What is the key difference between pooled data and panel data?
- What is unobserved heterogeneity and why does it cause bias in OLS?
- What are the three types of panel data classifications discussed in the lecture?
- What is attrition in the context of panel data and what problem does it cause?
- What is the difference between fixed effects and random effects in the error component model?
📘 Lecture 36 — Panel Data Models-II
📖 Overview: This lecture continues the discussion of panel data models, focusing on the Fixed Effect Model and Random Effect Model. It explains how to handle unobserved heterogeneity across entities, provides estimation methods like first differencing and deviations from means, introduces the random effects approach, and demonstrates practical implementation in Stata. This is critical for understanding how to analyze longitudinal data and choose the appropriate model for causal inference.
🗂️ Topics Covered
The lecture begins by revisiting the Fixed Effect Model with a composite error term, showing how unobserved heterogeneity becomes part of the intercept. It then covers two estimation methods for fixed effects: first differencing and deviations from means (within estimator). The Random Effect Model is introduced, assuming heterogeneity is uncorrelated with regressors. Finally, Stata implementation is demonstrated, including setting panel data, summary statistics, plotting, and model estimation with the Hausman test.
📝 Lecture Summary
Fixed Effect Model
Consider the model Yᵢₜ = β₀ + β₁X₁ᵢₜ + β₂X₂ᵢₜ + eᵢₜ, with eᵢₜ = μᵢ + uᵢₜ. Then Yᵢₜ = (β₀ + μᵢ) + β₁X₁ᵢₜ + β₂X₂ᵢₜ + uᵢₜ. The unobserved heterogeneity μᵢ is now part of the constant term but is different for different individuals. Individuals have different intercepts but common slopes. A diagram shows three different classes with three different intercepts but a common slope, which is the concept in the fixed effect model.
🔑 Definition — Fixed Effect Model: A panel data model that allows each entity (individual, firm, country) to have its own intercept, capturing time-invariant unobserved heterogeneity, while slopes are common across entities.
📐 Formula: Yᵢₜ = (β₀ + μᵢ) + β₁X₁ᵢₜ + β₂X₂ᵢₜ + uᵢₜ → The intercept is entity-specific (β₀ + μᵢ), but the effect of X on Y is the same for all entities.
📌 Example: If studying GDP of Pakistan, India, and Sri Lanka over time, each country gets its own intercept to account for unobserved time-invariant characteristics like geography or culture, while the effect of investment (gfcf) on GDP is assumed the same across countries.
Fixed Effect Model Estimation: First Difference
Eliminating unobserved heterogeneity by first differencing. Starting from Yᵢₜ = (β₀ + μᵢ) + β₁X₁ᵢₜ + β₂X₂ᵢₜ + uᵢₜ, take the model with one time lag: Yᵢₜ₋₁ = (β₀ + μᵢ) + β₁X₁ᵢₜ₋₁ + β₂X₂ᵢₜ₋₁ + uᵢₜ₋₁. Subtract: Yᵢₜ − Yᵢₜ₋₁ = β₁(X₁ᵢₜ − X₁ᵢₜ₋₁) + β₂(X₂ᵢₜ − X₂ᵢₜ₋₁) + (uᵢₜ − uᵢₜ₋₁). This gives ΔYᵢₜ = β₁ΔX₁ᵢₜ + β₂ΔX₂ᵢₜ + Δuᵢₜ. This can be generalized for more variables and works fine for two time periods.
🔑 Definition — First Difference Estimator: A method that eliminates unobserved fixed effects by subtracting the previous time period from the current time period for each entity, removing the entity-specific intercept.
📐 Formula: ΔYᵢₜ = β₁ΔX₁ᵢₜ + β₂ΔX₂ᵢₜ + Δuᵢₜ → Changes in Y are modeled as a function of changes in X, with the fixed effect μᵢ differenced out.
Fixed Effect Model Estimation: Deviation from Means (Alternative Approach)
We can use the deviations from means. Starting from Yᵢₜ = (β₀ + μᵢ) + β₁X₁ᵢₜ + β₂X₂ᵢₜ + uᵢₜ, taking deviations from mean eliminates the intercept: Yᵢₜ − Ȳᵢ. = β₁(X₁ᵢₜ − X̄₁ᵢ.) + β₂(X₂ᵢₜ − X̄₂ᵢ.) + uᵢₜ. The constant part is eliminated. Deviations from mean for each individual, averaged across all time periods. The model can be estimated by OLS, LSDV, etc. This is called the ‘within’ estimator. The ‘between’ estimator can be found by using the individual averages. The ‘overall estimator’ is the weighted average of within and between estimators.
🔑 Definition — Within Estimator: The fixed effect estimator obtained by regressing the deviations of Y from its entity-specific mean on the deviations of X from their entity-specific means, eliminating all time-invariant heterogeneity.
Random Effect Model
If correct weights are used, the combination of fixed (within) and between effect estimators is called the random effect estimator. The model is Yᵢₜ = β₀ + β₁X₁ᵢₜ + β₂X₂ᵢₜ + eᵢₜ, with eᵢₜ = μᵢ + uᵢₜ. When we assume μᵢ is drawn independently from some probability distribution, we are dealing with the random effect model. When unobserved heterogeneity is uncorrelated with regressors, panel data techniques are not needed to produce a consistent estimator. We must correct for serial correlation between observations of the same entity. If E(Xᵢₜ, eᵢₜ) ≠ 0, the Fixed Effect model may be used. When E(Xᵢₜ, eᵢₜ) = 0, the Random Effect model may be used to overcome the serial correlation of panel data.
To estimate the random effect model, we assume μᵢ is part of the error term eᵢₜ. We evaluate the structure of the error and apply appropriate Generalized Least Squares (with correct weights) to calculate efficient estimators. The following assumptions must hold:
- E(μᵢ) = E(uᵢₜ) = 0
- E(u²ᵢₜ) = σ²ᵤ and E(μ²ᵢ) = σ²μ
- E(uᵢₜ, μᵢ) = 0 for all i and t
- E(e²ᵢₜ) = σ²ᵤ + σ²μ
- E(Xₖᵢₜ, μᵢ) = 0 for all k, i, and t
🔑 Definition — Random Effect Model: A panel data model that treats unobserved heterogeneity as a random variable uncorrelated with the regressors, allowing the use of GLS to produce efficient estimates while correcting for serial correlation.
💡 Why this matters: The choice between fixed and random effects depends on whether unobserved heterogeneity is correlated with the regressors (use FE) or not (use RE). The Hausman test formally tests this assumption.
Panel Data Models using Stata
All panel data commands start with xt. We need to set the panel data first using xtset. If needed, we need to reshape our panel. The example uses a file panel1.dta with data from World Development Indicators for Pakistan, India, and Sri Lanka from 1991 to 2012 — a strongly balanced long panel.
The xtset command sets the data as panel data where both variables of cross-sectional and time should be numeric. Country is a string variable, so we create a numeric ID using: encode country, generate(countryId).
The xtsummarize command provides summary statistics specific to panel data.
💡 Why this matters: Properly setting panel data in Stata ensures that subsequent commands correctly account for the panel structure of the data.
xtline and Exploring Data
Consider that GDP is a function of gfcf (gross fixed capital formation), exports, and imports. The xtline gdp command plots the dependent variable by country over time, showing individual trends for each entity.
Fixed Effects in Stata
Use fixed-effects (FE) whenever you are only interested in analyzing the impact of variables that vary over time. FE explores the relationship between predictor and outcome variables within an entity (country, person, company). Each entity has its own individual characteristics that may or may not influence the predictor variables (e.g., being male or female could influence opinion, or political system could affect trade or GDP, or business practices could influence stock price).
When using FE, we assume that something within the individual may impact or bias the predictor or outcome variables, and we need to control for this. This is the rationale for the assumption of correlation between entity’s error term and predictor variables. FE removes the effect of those time-invariant characteristics from the predictor variables so we can assess the predictors’ net effect.
Least Square Dummy Variable (LSDV) model includes dummy variables for each entity to capture fixed effects. Another important assumption is that those time-invariant characteristics are unique to the individual and should not be correlated with other individual characteristics. If the error terms are correlated, FE is not suitable, and modeling that relationship (probably using random-effects) is needed — this is the main rationale for the Hausman test.
Random Effect Model in Stata
The random effect model is specified as Yᵢₜ = β₀ + β₁X₁ᵢₜ + β₂X₂ᵢₜ + eᵢₜ, where Y = gdp, X₁ = gfcf, X₂ = exports, and eᵢₜ = μᵢ + uᵢₜ. In Stata, the xtreg command with the re option estimates the random effects model.
Fixed or Random? Hausman Test
The Hausman test helps decide between fixed and random effects. The procedure is:
qui xtreg gdp gfcf exports, fe— estimate fixed effects modelestimates store fixed— store the resultsqui xtreg gdp gfcf exports, re— estimate random effects modelestimates store random— store the resultshausman fixed random— perform the test
Rejecting H₀ (the null hypothesis that random effects are consistent) means that fixed effects should be used.
🔑 Definition — Hausman Test: A statistical test that compares fixed effects and random effects estimates to determine whether the unobserved heterogeneity is correlated with the regressors. The null hypothesis is that random effects are consistent and efficient.
💡 Why this matters: Using the wrong model (e.g., RE when FE is required) leads to inconsistent estimates. The Hausman test provides an objective criterion for model selection in panel data analysis.
⭐ Key Takeaways
The Fixed Effect Model accounts for unobserved time-invariant heterogeneity by allowing each entity to have its own intercept, estimated via first differencing or the within estimator (deviations from means). The Random Effect Model treats heterogeneity as random and uncorrelated with regressors, requiring GLS for efficient estimation while correcting for serial correlation. The key decision between FE and RE depends on whether E(Xᵢₜ, μᵢ) = 0; the Hausman test formally tests this assumption, with rejection favoring the fixed effects model. In Stata, panel data must be set using xtset, and commands like xtreg with fe or re options implement the models. Understanding these models is essential for correctly analyzing longitudinal data and drawing valid causal inferences.
🧠 Quick Revision Questions
- What is the key difference between the Fixed Effect Model and the Random Effect Model in terms of how they treat unobserved heterogeneity (μᵢ)?
- How does the first difference estimator eliminate the fixed effect μᵢ? Write the resulting equation.
- What is the within estimator and how does it differ from the between estimator in panel data?
- State the null hypothesis of the Hausman test and explain what rejecting H₀ implies for model selection.
- Given panel data with E(Xᵢₜ, μᵢ) ≠ 0, which model (FE or RE) is appropriate and why?
📘 Lecture 37 — Panel Data Methods & Post Estimation Tests
📖 Overview: This lecture covers the complete procedure for panel data analysis in Stata, focusing on fixed and random effects estimation and the battery of post-estimation diagnostic tests required to validate model assumptions. It demonstrates how to test for time fixed effects, choose between fixed and random effects using the Hausman test, and diagnose problems like heteroskedasticity and serial correlation, along with their remedies.
🗂️ Topics Covered
The lecture begins with fixed effect estimation and testing for time fixed effects using joint significance tests on year dummies. It then covers the Hausman test to choose between fixed and random effects, the Breusch-Pagan LM test to decide between random effects and pooled OLS, tests for cross-sectional correlation in fixed effects models, the modified Wald test for groupwise heteroskedasticity, and Wooldridge’s test for serial correlation. Remedies including robust standard errors, xtregar for AR(1) errors, and cluster-robust standard errors are demonstrated using both the nlswork and grunfeld datasets.
📝 Lecture Summary
Fixed Effect Estimation
Fixed effects models control for time-invariant unobserved heterogeneity across entities (e.g., individuals, companies) by allowing each entity to have its own intercept. In Stata, the command xtreg with the fe option estimates the within-panel fixed effects model. The lecture uses nlswork data with dependent variable ln_wage and independent variables tenure, age, south, and union.
🔑 Definition — Fixed Effects (FE) Model: A panel data model that controls for time-invariant unobserved characteristics by focusing on within-entity variation over time. Each entity has its own constant term that captures all time-stable attributes.
📐 Formula: xtreg ln_wage tenure age south union, fe → estimates the within-panel fixed effects regression.
📌 Example: Using webuse nlswork, clear then running xtreg ln_wage tenure age south union, fe estimates how changes in tenure, age, and union status affect wage changes within each individual worker over time.
Testing Time Fixed Effects
Time fixed effects account for unobserved time-specific shocks that affect all entities equally (e.g., macroeconomic conditions, policy changes). The test checks whether all year dummy coefficients are jointly equal to zero. In Stata, include i.year in the model and use testparm i.year after estimation.
🔑 Definition — Time Fixed Effects: Dummy variables for each time period that capture common shocks across all entities in that period.
📐 Formula: xtreg ln_wage tenure age south union i.year, fe followed by testparm i.year
💡 Why this matters: If time fixed effects are jointly significant, ignoring them can bias coefficient estimates. The test result in the nlswork example showed rejection of the null (all year coefficients zero), meaning time dummies are needed.
Testing for Fixed Effects: Hausman test
The Hausman test formally compares fixed effects and random effects estimators to determine which model is appropriate. The null hypothesis is that the random effects model is correct (i.e., individual effects are uncorrelated with regressors). A significant test statistic indicates that random effects are inconsistent, so fixed effects is preferred.
🔑 Definition — Hausman Test: A specification test that checks whether the unique errors (entity-specific effects) are correlated with the regressors. If correlated, FE is consistent and RE is inconsistent.
📐 Formula:
xtreg ln_wage tenure age south union, fe
estimates store fixed
xtreg ln_wage tenure age south union, re
estimates store random
hausman fixed random
📌 Example: For the nlswork data, the Hausman test rejects the null (H₀ rejected), indicating that the fixed effect model is better than random effects.
Testing for Random Effects: LM test (Breusch and Pagan LM test for random effects)
The Breusch-Pagan Lagrange Multiplier (LM) test helps decide between a random effects regression and a simple OLS regression (pooled model). The null hypothesis is that variances across entities is zero — meaning no significant difference across units (no panel effect).
🔑 Definition — BP-LM Test: A test for the presence of random effects. If the null is not rejected, simple OLS (pooled regression) is appropriate.
📐 Formula:
xtreg ln_wage tenure age south union, re
xttest0
📌 Example: After running the random effects model, xttest0 gave a result where we fail to reject the null, meaning no random effects exist and simple OLS can be run instead.
Breusch-Pagan LM test for cross-sectional correlation in fixed effects model
This test checks for cross-sectional dependence (contemporaneous correlation) in the residuals of a fixed effect regression model. This is particularly problematic in macro panels with long time series (T > N). The null hypothesis is that residuals across entities are not correlated.
🔑 Definition — Cross-Sectional Dependence Test (xttest2): Tests whether residuals from different entities are correlated with each other in the same time period.
📐 Formula:
xtreg ln_wage tenure age south union in 1/25, fe
xttest2
📌 Example: Using only the first 25 observations to address the macro panel problem, the test accepted H₀, indicating no cross-sectional correlations found.
Testing for Heteroskedasticity
The modified Wald statistic tests for groupwise heteroskedasticity in the fixed effects model. The null hypothesis is homoskedasticity (constant variance of errors across groups/entities).
🔑 Definition — Modified Wald Test (xttest3): A test for groupwise heteroskedasticity in panel data fixed effects models.
📐 Formula:
xtreg ln_wage tenure age south union, fe
xttest3
📌 Example: In the nlswork example, the test indicated heteroskedasticity exists. The conclusion is to use the robust option with regression for both fixed and random effects models.
Testing for Serial Correlation: Wooldridge test
The Wooldridge test for serial correlation checks whether the idiosyncratic errors in a linear panel-data model are serially correlated. The null hypothesis is no serial correlation.
🔑 Definition — Wooldridge Test (xtserial): A test for first-order serial correlation in the errors of panel data models.
📐 Formula: xtserial ln_wage tenure age south union
📌 Example: The test concluded that serial correlation exists. The remedy is to use xtregar.
Remedy for Serial Correlation: xtregar
xtregar fits regression models for panel data when the residual is first-order autoregressive (AR(1)). It offers a within estimator for fixed-effects models and a GLS estimator for random-effects models.
🔑 Definition — xtregar: Panel data regression with AR(1) disturbances, handling both fixed and random effects specifications.
📐 Formula:
- Fixed-effects:
xtregar ln_wage tenure age south union, fe - Random-effects:
xtregar ln_wage tenure age south union, re
📌 Example: Since serial correlation exists in the nlswork example, xtregar ln_wage tenure age south union, fe was used to correct for AR(1) errors.
Example of Panel Data using grunfeld.dta
The lecture demonstrates a complete panel data workflow using the classic Grunfeld investment data, where company is the entity and year is the time variable.
📌 Example: The full procedure includes:
- Load data:
webuse grunfeld, clearthenxtset company year - Run FE:
xtreg invest mvalue kstock, fe - Test time FEs:
qui xtreg invest mvalue kstock i.year, fethentestparm i.year— p-value > 5%, so accept H₀ — no time FEs needed - Test for random effects:
qui xtreg invest mvalue kstock, rethenxttest0— reject H₀, panel effects exist - Hausman test: The test shows random effect model seems appropriate (RE preferred over FE)
- Heteroskedasticity:
xttest3— reject H₀, heteroskedasticity exists, use robust option (e.g.,xtreg invest mvalue kstock, fe robust) - Serial correlation:
xtserial invest mvalue kstock— reject H₀, serial correlation exists, usextregar - Remedy:
xtregar invest mvalue kstock, feandxtregar invest mvalue kstock, re— RE results shown
Panel Data: both HSK and SC!
When both heteroskedasticity and serial correlation exist simultaneously, use cluster-robust standard errors with the entity ID variable as the cluster input.
🔑 Definition — Cluster-Robust Standard Errors: Standard errors that are robust to both heteroskedasticity and arbitrary within-cluster serial correlation.
📌 Formula: xtreg invest mvalue kstock, fe cluster (company)
📌 Example: Using the cluster(company) option with xtreg produces standard errors that are completely robust to any kind of serial correlation and/or heteroskedasticity.
⭐ Key Takeaways
The panel data workflow requires sequential diagnostic testing after initial estimation: first test if time fixed effects are needed using testparm i.year, then decide between FE and RE using the Hausman test, and check whether panel effects exist at all using the Breusch-Pagan LM test. Post-estimation, test for heteroskedasticity using xttest3 (modified Wald test), for cross-sectional dependence using xttest2 in macro panels, and for serial correlation using xtserial. The remedy for serial correlation alone is xtregar, while the most robust solution for both heteroskedasticity and serial correlation is to use cluster-robust standard errors with the entity ID in the cluster() option.
🧠 Quick Revision Questions
- What command sequence tests whether time fixed effects are jointly significant, and what is the null hypothesis?
- How does the Hausman test determine whether fixed effects or random effects is the correct model?
- What does the Breusch-Pagan LM test (xttest0) help you decide between, and what does rejecting the null imply?
- What is the Stata command to test for groupwise heteroskedasticity in a fixed effects model, and what is the recommended remedy if heteroskedasticity is found?
- When both heteroskedasticity and serial correlation are present, what single Stata option provides robust inference?
📘 Lecture 38 — Qualitative and limited dependent variable models-I (Categorical dependent variable models)
📖 Overview: This lecture introduces categorical dependent variable models, focusing on situations where the outcome variable is qualitative rather than continuous. It explains why Ordinary Least Squares (OLS) is inappropriate for such data and presents logistic regression as the primary solution, covering binary, ordinal, and multinomial logistic regression models with their Stata implementations.
🗂️ Topics Covered
This lecture covers the concept of categorical variables and why OLS fails for them, the fundamentals of logistic regression including the logistic function and log of odds, interpretation of odds ratios, binary logistic regression in Stata with output interpretation, pseudo R-squared measures, ordinal logistic regression for ordered categories, and multinomial logistic regression for nominal categories without natural order.
📝 Lecture Summary
Variables with category
Categorical variables are variables that have categories and are normally qualitative in nature. They can be binary (two categories), multivariate (multiple categories), and can be ordinal (natural order exists) or nominal (no order). Examples include gender, color of eyes, educational status, and different outcomes of an event encoded in numbers. When the dependent variable is categorical, OLS is biased and inefficient because it violates key assumptions like normality and linearity.
Logistic Regression
Logistic regression is a type of regression analysis used to predict the outcome of a categorical variable (binary or others). The dependent variable has a limited number of outcomes and is predicted using a logistic function. Unlike OLS, logistic regression does not make any assumptions of normality, linearity, and homogeneity of variance for the independent variables. The minimum number of cases per independent variable is 10.
🔑 Definition — Logistic Function: F(t) = e^t / (e^t + 1) = 1 / (1 + e^(-t)) Where t is a linear function of the explanatory variables.
📐 Formula for probability of success: π(x) = 1 / (1 + e^(-(β₀ + β₁X))) This can be interpreted as the probability of the dependent variable equaling a 'success' or a 'case'.
📐 Formula for log of odds (logit): g(x) = ln[π(x) / (1 - π(x)] = β₀ + β₁X This is the natural logarithm of the odds.
The logistic function also has an equivalent formulation as a latent variable model. Let Y* be a continuous latent variable (unobserved random variable) where Y* = β₁X + ε, and ε ~ Logistic(0,1).
🔑 Definition — Odds Ratio: The ratio of probability of an event occurring to probability of an event not occurring. It measures the association between exposure and outcome.
Commands for logistic regression in Stata
- Binary logit:
logit - Ordered logit:
ologit - Multinomial logit:
mlogit
The syntax of the logit command is: logit depvar [indepvars] [if] [in] [weight] [, options]
Menu: Statistics > Binary outcomes > Logistic regression
Interpreting Results
In binary logistic regression, odds mean the ratio of favorable items to non-favorable items. The interpretation is: The log of odds changes by the amount of the coefficient for one unit increase in the independent variable. Prob > Chi2 = 0.0000 indicates that the model as a whole fits significantly better than an empty model (null model). The output shows coefficients, their standard errors, the z-statistic, associated p-values, and the 95% confidence interval of the coefficients. For example, for one unit increase in GAT score, the log odds of getting CGPA > 3 in Masters increases by 0.1787. If Gender is not significant (p-value > 0.05), it does not have a statistically significant effect on the outcome.
Pseudo Rsquare
Because OLS does not apply to logistic regression, an equivalent statistic to R-squared does not exist. Instead, pseudo R-squares are used because they look like R-squared (range from 0 to 1). Higher values indicate better model fit. Different pseudo R-squared measures can give different values, so caution is needed in interpretation. 💡 Why this matters: Unlike OLS R-squared which measures the proportion of variance explained, pseudo R-squared values cannot be interpreted as variance explained; they are relative measures of model improvement.
To get odds ratios instead of log of odds, use the or option in Stata.
Ordinal Logistic Regression
Ordinal logistic regression is used when the dependent variable is categorical with a natural order. Examples include: encoding in age brackets, educational grades encoded numerically, income brackets, size (small, medium, large, extra large), decision (unlikely, somewhat likely, very likely), and opinion (strongly agree, agree, etc.). The actual numerical values assigned to categories are irrelevant—only their order matters. Larger values are assumed to correspond to "higher" outcomes.
In Stata: Command Syntax: ologit depvar [indepvars] [if] [in] [weight] [, options]
Menu: Statistics > Ordinal outcomes > Ordered logistic regression
Multinomial Logistic Regression
Multinomial logistic regression is used when there is no order to the categories of the outcome variable—the categories are nominal. Examples include occupational choice (categories of job) and choice of specialization in degrees (Accounting, Finance, Marketing, etc.). The mlogit command fits maximum-likelihood multinomial logit models, also known as polytomous logistic regression.
In Stata: Menu: Statistics > Categorical outcomes > Multinomial logistic regression
Command Syntax: mlogit depvar [indepvars] [if] [in] [weight] [, options]
⭐ Key Takeaways
When the dependent variable is categorical, OLS is biased and inefficient, making logistic regression the appropriate alternative. Logistic regression uses a logistic function to model probabilities and can handle binary, ordinal, and nominal outcomes. The logit is the natural log of odds, and coefficients represent the change in log odds per unit increase in the independent variable. Stata provides three main commands: logit for binary, ologit for ordered, and mlogit for multinomial outcomes. Pseudo R-squared values provide a rough measure of model fit but should not be interpreted like OLS R-squared.
🧠 Quick Revision Questions
- Why is OLS biased and inefficient when the dependent variable is categorical?
- Write the logistic function formula and explain what it represents.
- What does the log of odds (logit) formula represent, and how is it interpreted in terms of coefficients?
- When should you use ordinal logistic regression versus multinomial logistic regression?
- What does a Prob > Chi2 value of 0.0000 indicate in logistic regression output?
📘 Lecture 39 — Qualitative and limited dependent variable models-II (Categorical dependent variable models)
📖 Overview: This lecture extends the discussion of categorical dependent variable models by introducing Probit Regression as an alternative to Logit. It covers the probit function, interpretation of coefficients, and Stata implementation for binary, ordinal, and multinomial probit models. Understanding this material is critical for modeling scenarios where the dependent variable takes discrete values (e.g., yes/no, ordered categories, or nominal choices).
🗂️ Topics Covered
The lecture begins with the definition and mechanics of Probit Regression, including the probit function based on the standard normal distribution. It explains how to interpret probit coefficients (changes in Z-scores, not marginal effects), presents an example of binary probit using Stata, and covers post-estimation tests. The lecture then moves to Ordinal Probit Regression for ordered categorical outcomes and concludes with Multinomial Probit Regression for nominal categorical outcomes, including Stata syntax and examples.
📝 Lecture Summary
Probit Regression
A type of regression analysis used to predict the probability of a categorical variable (binary or others). Examples of categorical variables are the same as in logit. The dependent variable has a limited number of outcomes. The dependent variable is predicted by using a probit function. The minimum number of cases per independent variable is 10.
🔑 Definition — Probit Function: Recall the standard normal distribution and Z-scores. Given any Z-score, ɸ(Z) is the cumulative normal distribution function. For any given Z, ɸ(Z) ∈ [0,1].
📐 Formula: Y = ɸ(Xβ + ε), then ɸ⁻¹(Y) = Xβ + ε. F(Y) = ɸ⁻¹(Y) is called the probit function.
🔑 Definition — Probit: Probit may be short for "probability unit." P(Y)=1.
💡 Why this matters: Xβ is the Z-value of a normal distribution. Higher the estimation value, more likely is the event to happen. A one unit change in the value of X brings β change in the Z-score of Y. The estimated curve is S-shaped.
📌 Example: The lecture shows a graph where red dots represent actual values of the categorical variable ('CGPA>3' = 1), and the curve shows the probit fit.
Binary probit command in Stata: probit
Syntax: probit depvar [indepvars] [if] [in] [weight] [, options]
Menu: Statistics > Binary outcomes > Probit regression
Consider the file logitProbit.dta. Run the Binary Probit regression.
Interpreting Results:
- Significance is almost as in logit.
- Model, as a whole is statistically significant (Pr > chi2) < 0.05.
- Coefficients: Change in Z-score or probit due to change in one unit of independent variable (they are less than one).
Interpretation of the coefficients:
- Not as in OLS.
- Not slope coefficient or marginal effects.
- The increase in probability due to a one-unit increase in a given independent variable/predictor depends both on the values of the other predictors and the starting value of the given predictors (different for different rows of observation).
- The predicted probability of CGPA>3 can be calculated as F(β₀ + β₁GAT + β₂AGE + β₃HRS), where βᵢ are the coefficients generated by the probit regression.
- Effect of change in one variable on the probability of getting CGPA>3 depends on the current value of a variable under consideration and also on the GIVEN/CONSTANT values of the other variables.
Tests after probit (fitness, different pseudo R squares): If fitstat is not installed, try ssc install fitstat.
Ordinal Probit Regression
Ordinal categorical dependent variable examples:
- Encoding in age brackets
- Educational Grades (encoded numerically)
- Income brackets encoded numerically
- Size (small, medium, large, or extra large)
- Decision (unlikely, somewhat likely, or very likely)
- Opinion (strongly agree, agree, etc.)
- The actual values are irrelevant.
- Larger values are assumed to correspond to "higher" outcomes.
In Stata:
Menu: Statistics > Ordinal outcomes > Ordered probit regression
Command Syntax: oprobit depvar [indepvars] [if] [in] [weight] [, options]
Magnitude of Coefficients differs from probit by a scale factor. Magnitude of Coefficients is not interpreted. The sign will matter.
Multinomial Probit Regression
No order to the categories of the outcome variable is found (i.e., the categories are nominal).
Examples:
- Occupational choice (categories of job)
- Choice of specialization in Degrees (Accounting, Finance, Marketing, etc.)
🔑 Definition — mprobit: Fits maximum-likelihood multinomial probit models, also known as polytomous probit regression.
In Stata:
Menu: Statistics > Categorical outcomes > Independent multinomial probit
Command Syntax: mprobit depvar [indepvars] [if] [in] [weight], [options]
⭐ Key Takeaways
Probit regression uses the cumulative standard normal distribution function to model the probability of categorical outcomes, with coefficients representing changes in Z-scores rather than direct probability changes. Unlike OLS, probit coefficients are not marginal effects; the impact on probability depends on the values of all predictors. The lecture covers three types: binary probit (for dichotomous outcomes), ordinal probit (for ordered categories where actual values are irrelevant but larger values correspond to higher outcomes), and multinomial probit (for nominal categories with no order). In Stata, the commands are probit, oprobit, and mprobit respectively, with post-estimation tests available via fitstat. The key distinction from logit is the use of the normal distribution instead of the logistic distribution.
🧠 Quick Revision Questions
- What function does probit regression use to transform the linear predictor into a probability?
- How do you interpret a probit coefficient for a one-unit change in an independent variable?
- What is the difference between ordinal probit and multinomial probit in terms of the dependent variable?
- In Stata, what command would you use to run an ordered probit regression?
- Why can't probit coefficients be interpreted as marginal effects like in OLS regression?
📘 Lecture 40 — Qualitative and limited dependent variable models-III & Censored Regression Models (Tobit Model)
📖 Overview: This lecture continues the discussion of qualitative and limited dependent variable models, covering the relationship between probability and odds ratio, marginal effects in probit models, and tests after logit/probit models such as the likelihood ratio test and Wald test. It then introduces censored regression models, specifically the Tobit model, for situations where the dependent variable is incompletely observed, and demonstrates its implementation in Stata.
🗂️ Topics Covered
The lecture first maps the relationship between probability, odds ratio, and log-odds, then explains how marginal effects are calculated in probit models and implemented in Stata. It covers the likelihood ratio test and Wald test for model comparison and joint significance testing. The second half introduces truncated versus censored data, the structure of the Tobit model for latent variables censored at a threshold, and its application using Stata including interpretation of output.
📝 Lecture Summary
Probability Vs. Odd Ratio
The lecture presents a table mapping the relationship between probability, odds ratio, and log-odds (ln odds). Probability ranges from 0 to 1, odds ratio ranges from 0 to ∞, and log-odds ranges from −∞ to ∞. When probability = 1/2, odds ratio = 1 and log-odds = 0 (even odds). When probability > 1/2, odds ratio > 1 and log-odds is positive (favor). When probability < 1/2, odds ratio < 1 and log-odds is negative (against).
🔑 Definition — Odds Ratio: The ratio of the probability of an event occurring to the probability of it not occurring. Formula: Odds Ratio = Probability of x / (1 − Probability of x).
📐 Formula: Probability = Odds Ratio / (1 + Odds Ratio) → This converts odds back to probability.
📌 Example: If probability = 1/3, then odds ratio = (1/3) / (2/3) = 1/2 (against, 1 to 2). If probability = 2/3, then odds ratio = (2/3) / (1/3) = 2 (favor, 2 to 1).
💡 Why this matters: The coefficients from logit/probit models represent the change in probability or odds ratios, not the probability or odds themselves. The formulas above apply to the variables, not the coefficients.
Marginal Effects
In probit models, the slope (marginal effect) is not simply the coefficient as in OLS. The marginal effect of a predictor on the probability that Y=1 depends on both the values of other predictors and the starting value of the predictor itself.
📐 Formula: ∂ℙ(Yᵢ = 1 | X₁ᵢ, ..., Xₖᵢ; β₀, ..., βₖ) / ∂Xₖᵢ = βₖ × ɸ(β₀ + ΣβₖXₖᵢ)
Here, ɸ(·) is the standard normal probability density function. The increase in probability due to a one-unit increase in a predictor depends on all other predictors and the starting value of the given predictor — it differs for different rows of observations.
🔑 Definition — Marginal Effects in Stata: Using the command margins, dydx(*) after a probit regression calculates the average marginal effect.
📌 Example: With file logitProbit.dta, after probit cgpm3 gat age hrs gender, running margins, dydx(*) shows that one unit increase in gat increases the probability of CGPA>3 by 0.0128985.
Tests after logit/probit models
Likelihood ratio test is used for both logit and probit models. It estimates two models (e.g., empty vs. full, or restricted vs. unrestricted) and compares them. The test statistic is distributed chi-squared with degrees of freedom equal to the difference in degrees of freedom between the two models. Significance means the model improves.
📌 Example: In Stata, run probit cgpm3 (empty model), store as m1, then probit cgpm3 gat age hrs gender (full model), store as m2, then lrtest m1 m2. If the p-value is less than 0.01, including all variables together improves the model. This test is used when the first model is nested in the second.
Wald test estimates similarly but is better as it requires running only one model. It tests if the parameters of interest are jointly equal to zero.
📌 Example: In Stata, after probit cgpm3 gat age hrs, run test gat age hrs. If the result shows H₀ is rejected at 10%, all coefficients of variables (gat, age, hrs) are not jointly zero.
Censored Data Regression Models: The Tobit Model
OLS is inefficient when the dependent variable is incompletely observed or when the dependent variable is observed completely but the selected sample is not representative of the population.
Truncated Data: Observations on both dependent and independent variables are lost. Example: only small firms included, low income respondents only.
Censored Data: Observations on the dependent variable only are lost (or limited). Examples: income top-coded to 50,000; time bottom-coded to 10-minute chunks.
Tobit Model: Structure Suppose y* is a latent variable that is observed partially for values greater than θ.
📐 Formula: y*ᵢ = Xᵢβ + εᵢ, where εᵢ ~ N(0, σ²)
The observed y is defined as: y = y* if y* > θ y = θ if y* ≤ θ
Since data is often censored at zero, the model becomes: y = y* if y* > 0 y = 0 if y* ≤ 0
📌 Examples where Tobit model may be applied:
- Time use surveys: 10-minute time chunks
- Glucometers: reading "Error" or not more than a specific value (e.g., 500 mg/dL)
- GAT: students answering all 100 questions may have different IQ levels and/or aptitude
Tobit Model using Stata
Tobit Model Stata Command: tobit
Syntax: tobit depvar [indepvars] [if] [in] [weight] , ll[(#)] ul[(#)] [options]
Menu: Statistics > Linear models and related > Censored regression > Tobit regression
📌 Example: Using file logitProbit.dta with variable gat. For left censoring at 60, use tobit gat age hrs gender, ll(60). If there are 40 observations with 10 having gat < 60, even after censoring there are 40 observations. Both left and right censoring can be used.
Interpreting Tobit Output:
- P-value of Chi2: Good fit; at least one regression coefficient is non-zero
- Log likelihood: Used for LR test
- McFadden Pseudo R-square: Model fit measure
- Observation Summary: Shows how many values have been censored (e.g., right censored 12 considered as having 75 marks)
- Regression Coefficients: e.g., age — higher the age, greater the GAT score; one year increase in age may increase GAT score by 3.2 on average
- P-values: Show significance of coefficients
- Estimated standard error of the regression: Like RMSE in OLS
⭐ Key Takeaways
Probability and odds ratio are related by simple formulas, but coefficients from logit/probit models represent changes in probability, not the probability itself. Marginal effects in probit models depend on the values of all predictors and vary across observations, so Stata's margins, dydx(*) command is essential. The likelihood ratio test and Wald test are both used to assess model fit and joint significance, with the Wald test requiring only one model. The Tobit model is necessary when the dependent variable is censored (partially observed), such as top-coded income or time chunks, and OLS would be inefficient for such data.
🧠 Quick Revision Questions
- If the odds ratio is 3, what is the corresponding probability?
- Why do marginal effects in probit models differ across observations?
- What is the key difference between the likelihood ratio test and the Wald test in terms of number of models required?
- In the Tobit model, when y* ≤ θ, what value does the observed y take?
- What does the McFadden Pseudo R-square in Tobit output represent?
📘 Lecture 41 — Forecasting-I
📖 Overview: This lecture introduces the concept of forecasting in econometrics, distinguishing it from mere prediction. It covers the meaning, types, and methods of forecasting, including various time series techniques. Understanding these fundamentals is critical for using econometric models to make informed statements about future events.
🗂️ Topics Covered
The lecture begins by defining forecasting and differentiating it from prediction, then outlines the requirements for good forecasting and common methods. It categorizes forecasts into types: ex-ante vs. ex-post, mean vs. individual, conditional vs. unconditional, and qualitative vs. quantitative. The lecture then explores patterns in time series data (trend, seasonal, cyclical, irregular) and presents several time series forecasting models: last period, simple/weighted average, moving averages, seasonal indices, exponential smoothing, and trend methods. Finally, it introduces associative or causal forecasting.
📝 Lecture Summary
Meaning and Types of Forecasting
Forecasting is a probabilistic statement about the future based on a systematic procedure. In econometrics, it is defined as “Predicting a known or unknown value of a dependent variable based on known or unknown values of the independent variables by using an econometric model.” Good forecasting requires that there are patterns or regularities to capture, that these patterns provide information about the future, and that the econometric model can capture them. However, irregular variations and shocks cannot be predicted.
🔑 Definition — Prediction vs. Forecasting: Prediction is an inference from laws of nature, while Forecasting is more probabilistic. 💡 Why this matters: Forecasting acknowledges uncertainty and uses systematic models, unlike deterministic predictions.
Methods of forecasting include guesswork, leading indicators, extrapolation, time series models, and econometric forecasting models. Forecasts are never 100% accurate due to unknown factors (both known unknowns and unknown unknowns) and the problem of using static models for a dynamic world.
Types of Forecast
- Ex Ante and Ex Post Forecasts: Ex post forecasts are always unconditional. Ex ante forecasts may or may not be unconditional.
- Example: (Y_t = f(X_{t-3}, X_{t-4}))
- Mean Forecast and Individual Forecast: Individual Forecast predicts the individual value of the dependent variable; Mean Forecast predicts the expected value.
- Conditional and Unconditional Forecast: Unconditional Forecast uses known values of explanatory variables; Conditional Forecast uses unknown values of explanatory variables.
- Qualitative and Quantitative Forecast: Qualitative Forecast is subjective (opinion, surveys); Quantitative Forecast is based on mathematical models.
Patterns in Time Series Data
- Trend: Steady growth or decline over time in the long run.
- Seasonal Variations: Variations in different parts of the year (short run).
- Cyclical Variation: Upward or downward movement over the medium term (e.g., business cycle).
- Irregular or Random Variations or Shocks: Unpredictable variation without any pattern (e.g., war, natural disasters).
Time Series Models for Forecasting
The lecture uses hypothetical demand data from 2006 to 2013, converted to annual data.
a) Last Period Method: Uses the value of the previous time period as a forecast. 📌 Example: For 2014, forecast = 85 (the demand of 2013).
b) Simple or Weighted Average Method: Uses the average of previous demands as a forecast.
- Simple Average: For 2008, forecast = (61+62)/2 = 61.5. For 2009, forecast = (61+62+66)/3 = 63.
- Weighted Average: Weights are assigned (e.g., 0.6 for the previous year and 0.4 for two years back). For 2008, forecast = 0.662 + 0.461 = 61.6.
c) Simple or Weighted Moving Averages: Uses the moving average of a fixed number of previous periods (e.g., 2 years). For 2008, forecast = (61+62)/2 = 61.5. For 2009, forecast = (62+66)/2 = 64.
d) Seasonal Indices: Uses seasonal patterns in the data. (Not elaborated with example here.)
e) Exponential Smoothing: A weighted technique where more weight is given to recent observations. The forecast is: (F_{t+1} = F_t + \alpha (A_t - F_t)), where (\alpha) is a smoothing coefficient (0 to 1). 🔑 Formula: (F_{t+1} = F_t + \alpha (A_t - F_t)) → The new forecast is the old forecast plus a fraction of the previous forecast error. 📌 Example: With (\alpha = 0.1), forecast for 2007 = 61 + 0.1(62-61) = 61.1. For 2008, forecast = 61.1 + 0.1(66-61.1) = 61.4. 💡 Why this matters: This method smooths random fluctuations and is adaptive to recent changes.
f) Trends: Uses least squares to fit a regression line to forecast. The equation is (Y = a + bT). 📌 Example: (Y = 55.393 + 3.607 * T). For 2014 (T=9), forecast = 55.393 + 3.607*(9) = 87.857.
Associative or Causal Forecast
This depends on associated variables, not time. For example, demand may depend on price. A regression line like (Demand = a + b * Price) is used. 📌 Example: (Demand = 500.49 - 44.84 * Price). For 2014 with a forecasted price of 9.3, forecast = 500.49 - 44.84*(9.3) = 83.47.
⭐ Key Takeaways
Forecasting is a probabilistic, systematic procedure for predicting future events; it is never 100% accurate. Forecasts are categorized as ex-ante/ex-post, mean/individual, unconditional/conditional, and qualitative/quantitative. Time series data exhibit trend, seasonal, cyclical, and irregular patterns which inform model choice. Common forecasting models include last period, simple/weighted average, moving average, exponential smoothing, and trend methods. Finally, associative causal forecasts use regression on explanatory variables like price, rather than time.
🧠 Quick Revision Questions
- What is the difference between a prediction and a forecast in econometrics?
- What are the three requirements for a good forecasting model?
- Explain the difference between an unconditional forecast and a conditional forecast. Provide an example.
- Describe the exponential smoothing forecasting method. What is the role of the smoothing constant (alpha)?
- How does an associative/causal forecast differ from a trend-based forecast? Give an example of a variable that might be used in an associative forecast.
📘 Lecture 42 — Forecasting-II
📖 Overview: This lecture focuses on advanced forecasting techniques, specifically how to handle seasonal variation in time series data and how to evaluate the performance of different forecasting models. It is critical for ensuring forecasts are accurate and reliable for business decision-making, and introduces key metrics to compare model efficacy.
🗂️ Topics Covered
This lecture covers the calculation of seasonal indices to adjust forecasts for quarterly patterns. It then introduces several forecasting performance measures like Mean Absolute Error (MAE) and Root Mean Square Error (RMSE) to evaluate model accuracy. The concept of tracking signals is explained for monitoring forecast bias over time. Finally, it discusses the variance of forecast error, breaking it down into model variance and estimation variance, and how to compute it, for instance in Stata.
📝 Lecture Summary
Seasonal Variation and forecasting
The lecture begins by demonstrating seasonal variation in data, where values show a recurring pattern within a year. In the example, values are generally high in the second quarter and lowest in the first quarter. To make accurate forecasts, these seasonal effects must be accounted for.
Calculating Seasonal Index
A seasonal index is a multiplier that adjusts forecasts to reflect typical seasonal patterns. The index is calculated by first reshaping data into quarterly columns and computing the average for each quarter across all years. The grand average (average of all quarterly averages) is then found.
🔑 Definition — Seasonal Index: A factor used to adjust a forecast for a specific season (e.g., quarter) so that it reflects the typical pattern of variation within a year.
📐 Formula: Seasonal Index for a quarter = (Quarterly Average of that quarter) / (Grand Average of all quarterly averages).
📌 Example: From the data, quarterly averages for Q1-Q4 are 16.25, 20, 18.5, and 16.75. The grand average is (16.25 + 20 + 18.5 + 16.75) / 4 = 17.90625. The seasonal index for Q1 is 16.25 / 17.90625 = 0.9075. The sum of all seasonal indices always equals 4 (for quarterly data).
💡 Why this matters: To produce a seasonally adjusted forecast, you first make a forecast using any method (like a trend projection), then multiply that forecast by the relevant seasonal index.
📌 Example: A regression on time gives the formula: Demand = 14.24395 + 0.221957 (Time). For the four quarters of 2014, Time values are 33, 34, 35, and 36, yielding unadjusted forecasts (e.g., 21.57, 21.79, 22.01, 22.23). These are adjusted by multiplying by the seasonal indices (0.9075, 1.1239, 1.0332, 0.9354), giving the final adjusted forecasts (e.g., 19.57, 24.49, 22.74, 20.80).
Measuring Forecasting Performance
To compare different forecasting methods, we use performance measures based on the forecast error, which is the difference between the actual value and the forecasted value (Y_t - F_t). These measures are used on Ex Post Forecasts, where actual values are known.
🔑 Definition — Forecast Error: The difference between the actual value of a variable and its forecasted value (Y_t - F_t).
The lecture lists several key performance measures:
- Mean Forecast Error (MFE): The arithmetic mean of forecast errors. Its weakness is that positive and negative errors can cancel each other, giving a misleadingly low error.
- Mean Absolute Error (MAE) or Mean Absolute Deviation (MAD): The mean of the absolute values of forecast errors. This solves the cancellation problem.
- Mean Absolute Percent Error (MAPE): The mean of the absolute errors expressed as a percentage of the actual values.
- Root Mean Square Error (RMSE): The square root of the mean of squared errors. It gives more weight to large errors.
- Root Mean Square Percent Error (RMSPE): The square root of the mean of squared percent errors. Useful when the variable's scale is large.
- Theil’s Inequality Coefficient (TIC): A scale-invariant measure that always falls between 0 and 1, where 0 indicates a perfect fit.
Tracking Signals in Forecasting
A tracking signal is used to monitor whether a forecasting model is consistently biased over time.
🔑 Definition — Tracking Signal (TS): A measure used to detect bias in a forecasting model by comparing the cumulative forecast error to the Mean Absolute Deviation (MAD).
📐 Formula: TS = Cumulative Error / MAD
📌 Example: With data from 2008-2013, forecast errors are calculated. The cumulative error builds over time. For instance, in 2008, the cumulative error is -0.21, and the MAD is 0.21, giving a TS of -1.0. A safe range (e.g., -5 to 5) is selected, and the TS is plotted over time. If it stays within the channel, the model is considered unbiased.
Variance of Forecast Error
The variance of the forecast error Var(e_t+h) has two components: the model variance (σ²) and the estimated variance Var(Ŷ_t+h).
🔑 Definition — Variance of Forecast Error: The total uncertainty associated with a forecast, composed of the inherent random error of the model and the error from estimating the model's parameters.
📐 Formula: Var(e_t+h) = σ² + Var(Ŷ_t+h)
The standard error of the forecast se(e_t+h) is sqrt(σ² + se(Ŷ_t+h)²).
💡 Why this matters: In practice, the standard error of the forecast (se_forecast or stdf in Stata) is larger than the standard error of the prediction (se_prediction or stdp in Stata) because it includes the model's irreducible error.
📌 Example: In the Stata output, the stdf value (e.g., 0.9105) is consistently larger than the stdp value (e.g., 0.5003) because stdf includes the additional model variance component.
⭐ Key Takeaways
A student must remember that seasonal indices are multipliers derived from historical quarterly averages and must sum to 4 for quarterly data, used to adjust any base forecast. The six forecast error measures—MFE, MAE/MAD, MAPE, RMSE, RMSPE, and TIC—each have specific strengths, and RMSE is particularly common. A tracking signal (Cumulative Error / MAD) is crucial for monitoring forecast bias, with a standard acceptable range of -5 to 5. Finally, the standard error of a forecast (stdf) is always larger than the standard error of prediction (stdp) because it includes the model’s inherent variance.
🧠 Quick Revision Questions
- Why is the Mean Forecast Error (MFE) considered a potentially misleading measure of forecasting performance?
- What is the formula for calculating a Seasonal Index, and why must the sum of indices for quarterly data equal 4?
- How is a Tracking Signal calculated, and what does a value consistently outside the range of -5 to 5 indicate?
- A regression forecast yields a standard error of prediction (stdp) of 0.5, and the model's RMSE is 0.8. What is the approximate standard error of the forecast (stdf)?
- What is the primary difference between Root Mean Square Error (RMSE) and Mean Absolute Error (MAE)?
📘 Lecture 43 — Time Series, Cointegration and Error Correction-I
📖 Overview: This lecture introduces the fundamental concepts of time series analysis, distinguishing between stationary and nonstationary processes. It explains why testing for non-stationarity is critical in econometrics to avoid spurious regressions and presents the two most common unit root tests: the Augmented Dickey-Fuller test and the Phillips-Perron test, including their implementation in Stata.
🗂️ Topics Covered
The lecture begins by defining time series analysis (univariate vs. multivariate) and the historical divergence between time-series analysts and econometricians. It then defines moments, explains strict and weak stationarity, and contrasts these with non-stationarity. The two main types of non-stationarity (random walk with drift and deterministic trend) are introduced along with their required treatments (differencing vs. detrending). The concept of integration order (I(d)) is presented, followed by a detailed explanation of unit root testing: why it matters, and how to perform both the Augmented Dickey-Fuller (dfuller) and Phillips-Perron (pperron) tests in Stata, with examples using the sunspot and dow1 datasets.
📝 Lecture Summary
What is a time series?
An analysis of a single sequence of data is called univariate time-series analysis. An analysis of several sets of data for the same sequence of time periods is called multivariate time-series analysis. Historically, econometricians emphasized economic theory and contemporaneous relationships, while time-series analysts preferred to let the data determine the model. Since the mid-1970s, these two approaches have been converging.
Stationary and Nonstationary time series
Moments are specific quantitative measures of the shape of a set of points. The first raw moment (∑X/n) is the mean. The first moment about mean is zero. The second moment about mean is the variance.
The joint distribution of X(t₁), X(t₂), X(t₃)...X(tₙ) is complicated, so we define:
- Mean = μ(X) = E(Xₜ)
- Variance = σ²(t) = E(X²)
- Autocovariance = γ(t₁, t₂) = Cov(Xₜ₁, Xₜ₂)
The autocovariance is the covariance of the variable against a time-shifted version of itself (it is the variance if t₁=t₂=t).
Strict or Strong Stationary
A series is called strict stationary if the joint distribution of any set of n observations X(t₁), X(t₂), X(t₃)...X(tₙ) is the same as the joint distribution of X(t₁+h), X(t₂+h), X(t₃+h)...X(tₙ+h) for all n and h.
All moments are independent of t. The mean, variance, and all higher order moments of the joint distribution of any combination of variables X(t₁), X(t₂), X(t₃)...X(tₙ) are constant and independent of t. This is a very strong assumption. Statistical properties do not change over time.
Define h = t₂ - t₁ and call it a lag. The autocovariance function γ(t₁, t₂) = γ(h) = Cov(Xₜ, Xₜ₊ₕ) is the autocovariance function (acvf) at lag h. Var(Xₜ) = Var(Xₜ₊ₕ) = σ² = γ(0). The autocorrelation function at lag h is defined as ρ(h) = γ(h)/γ(0). A plot of ρ(h) is called a correlogram.
Second Order or Weak Stationary (covariance stationarity)
A series is called weakly stationary if its mean and variance do not depend on t (are constant) and the acvf depends only on the lag h. Stationary series revert in the long run to their mean.
Non-Stationarity
In real life, most of the data is non-stationary. Variables that increase over time are non-stationary. Mean and variance are not constant over time. We need differencing and/or detrending. We can define a non-stationary model as Xₜ = μₜ + eₜ where mean μₜ is a function of time (linear or non-linear) and eₜ is a second order stationary series.
An Autoregressive Model specifies that the output variable depends linearly on its own previous values. Time series models include ARMA, ARIMA, etc. (not discussed in this lecture). OLS should not be used on non-stationary data (e.g., problem of spurious regression). We usually can transform variables by taking differences or using lags if the data becomes stationary at difference or lag.
Types of Non-Stationarity
- Random Walk with Drift: Yₜ = μ + Yₜ₋₁ + eₜ
- Deterministic Trend Process: Yₜ = β₀ + β₁t + eₜ
To induce stationarity, both will require different treatment: differencing for the random walk and detrending for the deterministic trend.
If a non-stationary series Yₜ is differenced d times in order to become stationary, it is said to be integrated of order d. If Yₜ ~ I(d) then ΔᵈYₜ ~ I(0). I(0) is a stationary series; it will cross the mean frequently. I(1) is a series containing one unit root. Most economic and financial series contain a single unit root (some may be stationary). However, prices have been seen in various researches to have 2 unit roots.
UNIT ROOT TEST
A unit root test tests whether a time series variable is non-stationary using an autoregressive model. The famous tests include the Augmented Dickey–Fuller test and the Phillips-Perron test. The null hypothesis for these tests is the existence of a unit root.
Why do we need to test for Non-Stationarity?
- The stationarity or non-stationarity of a series can strongly influence its behavior and properties.
- Spurious regressions: If two variables are trending over time, a regression of one on the other could have a high R-square even if the two are totally unrelated.
- The parameters are misleading.
- If variables in the model are not stationary, the usual “t-ratios” will not follow a t-distribution, so various tests will not be valid.
Augmented Dickey-Fuller unit-root test (dfuller)
dfuller performs the augmented Dickey-Fuller test that a variable follows a unit-root process. It adds lagged differences to the model. The null hypothesis is that the variable contains a unit root, and the alternative is that the variable was generated by a stationary process. You may optionally exclude the constant, include a trend term, and include lagged values of the difference of the variable in the regression.
Syntax: dfuller varname [if] [in] [, options]
Menu: Statistics > Time series > Tests > Augmented Dickey-Fuller unit-root test
🔑 Definition — Augmented Dickey-Fuller test: A unit root test that adds lagged differences of the dependent variable to the regression to account for serial correlation in the error term.
📐 Formula — The Dickey-Fuller regression models are:
- No constant, no time trend: ΔYₜ = γYₜ₋₁ + uₜ
- Constant, without time trend: ΔYₜ = α + γYₜ₋₁ + uₜ
- Constant and time trend: ΔYₜ = α + γYₜ₋₁ + γt + uₜ
Use constant (drift) when the series fluctuates against a non-zero mean.
Phillips-Perron unit-root test (pperron)
pperron performs the Phillips-Perron test that a variable has a unit root. The null hypothesis is that the variable contains a unit root, and the alternative is that the variable was generated by a stationary process. pperron uses Newey-West standard errors to account for serial correlation (so it allows for autocorrelated residuals), whereas the augmented Dickey-Fuller test implemented in dfuller uses additional lags of the first-difference variable.
Syntax: pperron varname [if] [in] [, options]
Menu: Statistics > Time series > Tests > Phillips-Perron unit-root test
💡 Why this matters: The Phillips-Perron test is more robust than the ADF test to unspecified autocorrelation in the errors, as it uses non-parametric corrections.
Examples (from Stata output)
- Sunspot data: The
tsline spotgraph appears stationary. Thedfuller spottest output is shown but without explicit p-values in the text. - Dow Jones data: The
tsline dowclosegraph shows a random walk with non-zero drift. Thedfuller dowclosetest output indicates the coefficient of L1 is not significant, suggesting a unit root. Thedfuller D.dowclosetest is used after differencing. - Key options explained:
trend: Includes a trend term in the regression; the null hypothesis is a random walk, perhaps with drift. Cannot be used withnoconstantordrift.drift: Indicates the process under the null hypothesis is a random walk with nonzero drift. Cannot be used withnoconstantortrend.regress: Specifies that the associated regression table appear in the output.lags(#): Specifies the number of lagged difference terms to include.
- Phillips-Perron example: The
pperron dowcloseoutput is provided, testing for a unit root in the Dow Jones series.
⭐ Key Takeaways
The most critical concepts from this lecture are: (1) A stationary series has constant mean, variance, and autocovariance that depends only on lag, while non-stationary series have time-dependent moments and require differencing or detrending. (2) Spurious regression occurs when unrelated trending variables yield high R-squared values, making unit root testing essential before any regression. (3) The Augmented Dickey-Fuller test adds lagged differences to correct for autocorrelation, while the Phillips-Perron test uses Newey-West standard errors for the same purpose. (4) Both tests have a null hypothesis of a unit root (non-stationarity), and the alternative is stationarity. (5) In Stata, the dfuller and pperron commands implement these tests, with options for including a constant (drift), a trend, or neither, depending on the characteristics of the series.
🧠 Quick Revision Questions
- What is the difference between strict stationarity and weak (covariance) stationarity?
- Why is it problematic to run OLS regression on two independent non-stationary time series?
- What are the two main types of non-stationarity discussed in the lecture, and what is the appropriate treatment for each?
- What is the null hypothesis in both the Augmented Dickey-Fuller and Phillips-Perron unit root tests?
- How do the Augmented Dickey-Fuller test and the Phillips-Perron test differ in their approach to handling autocorrelation in the residuals?
📘 Lecture 44 — Time Series, Cointegration and Error Correction-II
📖 Overview: This lecture addresses what to do when time series data are non-stationary. It introduces cointegration as a method to preserve long-run relationships between integrated variables and presents the Error Correction Model (ECM) to model short-run dynamics while maintaining long-run equilibrium. The lecture provides a step-by-step procedure for the Engle-Granger cointegration test and ECM estimation using Stata.
🗂️ Topics Covered
The lecture covers the problem of non-stationarity in time series and two approaches: differencing (short-term) and cointegration (long-term). It explains the concept of cointegration, the Engle-Granger cointegration test procedure, the Granger Representation Theorem linking cointegration to error correction, and the specification and estimation of the Error Correction Model. A detailed example using Pakistani data on GFCF and imports from the ECM.dta file illustrates the entire process.
📝 Lecture Summary
What to do in case of non-stationarity?
Two main approaches are discussed. Differencing throws out long-term properties of the series and is good for short-term modeling only. Cointegration, introduced by Granger, preserves the long-run relationship between variables.
Cointegration
Two series of variables may be integrated, but their difference (or any linear combination) may be stationary. This means that each variable wanders quite far from its mean, but the two series wander very near each other. The value/location of one variable could be told by looking at the other variable. They have an equilibrium relationship (never expected to drift too far). Deviations from this equilibrium will be corrected over time.
Cointegration & Error Correction Model Using Stata
Engle-Granger Cointegration Analysis: STEPS
- Test individual variables for unit root
- Estimate the static regression
- Test for unit roots in the error of the static regression; if residuals are stationary, series are cointegrated.
- Finally, we can use Error Correction Model
Granger Representation Theorem: Two or more integrated time series that are cointegrated have an error correction representation. If x and y are cointegrated, we can model y and x as being in an error correcting relationship. It has y and x being in an equilibrium relationship, with the short-run behavior of y being a function of the short-run behavior of x and an equilibrating factor. It estimates the speed at which a dependent variable Y returns to equilibrium after a change in an independent variable X.
🔑 Definition — Error Correction Model (ECM): A model that captures both the short-run dynamics and the long-run equilibrium relationship between cointegrated variables.
📐 Formula: ∆Yₜ = β∆Xₜ + ρ(Yₜ₋₁ − γXₜ₋₁) + εₜ Where Yₜ₋₁ − γXₜ₋₁ is the predicted error generated from a basic regression Y on X. εₜ is stationary (test for this with Dickey-Fuller). β is the short-run effect of x on y and ρ is the speed of equilibration, with γ giving the long-run relation between y and x.
💡 Why this matters: ECM is normally used on non-stationary data but can be used for stationary data.
Cointegration and Error Correction Model in Detail
Stationary Data means that data has a finite mean and variance that do not depend on time. Data reverts to mean in the long run. It crossed the mean quite often.
Integrated time series data:
- Does not revert to the mean
- Usually moves in a random walk
- Previous changes are reflected in the current value
- May have infinite variance and no appropriate mean
- Shocks are permanently incorporated
If a non-stationary series Yₜ is difference d times in order to become stationary, it is said to be integrated of order d — denoted I(d).
Two series are cointegrated if:
- They are integrated of the same order
- There is a linear combination of the two series that is stationary i.e. integrated of order zero I(0)
- Cointegrated data do not drift very far from each other.
- Deviation from equilibrium will be corrected over time
Critical Values and Power
For the Engle-Granger test, special critical values are used instead of standard t-distribution values:
| Statistics Name | 1% | 5% | 10% |
|---|---|---|---|
| DF | 4.07 | 3.37 | 3.03 |
| ADF | 3.77 | 3.17 | 2.84 |
Example: GFCF and IMPORTS (Pakistan, 1983-2012)
Using the file ECM.dta containing Pakistani data (GDP, GFCF, imports) from WDI for years 1983 to 2012, the lecture examines whether GFCF and IMPORTS are cointegrated.
Both GFCF and Imports are integrated at first difference — they are both I(1), meaning they are integrated at the same level.
Engle-Granger Test Steps Applied:
- Run a basic regression (long run): regress GFCF on imports
- Predict the errors: generate residuals
- Run the regression of first difference of residuals on lag of residuals and on lag of first difference of residuals
If the coefficient of lag of residuals is significant, the series are cointegrated. IMPORTANT: the t-values reported in simple regression are not appropriate; we use the EG critical values.
📌 Example — Test Results: The coefficient of first lag of residuals is -0.5926 and the t-value is -3.42. The critical value at 5% is -3.37. Our value, -3.42 < -3.37, so the hypothesis of no cointegration is rejected. The series are cointegrated. If the test statistic < critical value, we reject the null hypothesis that the least square residuals are non-stationary (no cointegration).
ECM Estimation Results from ECM.dta: Using Stata commands:
tsset year
regress gfcf imports
predict rhat, residual
Then running the ECM with residuals: The short-run effect of imports on GFCF is positive and significant (β). The long-term relation is established by the coefficient -0.3765 (ρ) which is also significant. The speed shows that the deviations from equilibrium are corrected at 37.5% in one time period.
💡 Why this matters: Additional or alternative lags and deterministic terms may be added to the ECM specification.
⭐ Key Takeaways
The most critical message is that when two non-stationary series are integrated of the same order and their linear combination is stationary, they are cointegrated, meaning they share a long-run equilibrium relationship. The Engle-Granger two-step procedure involves testing unit roots individually, running a static regression, and testing residuals for stationarity using special critical values. Once cointegration is established, the Error Correction Model (ECM) must be used, which includes both short-run dynamics (βΔX) and an error correction term (ρ * lagged residual) that captures the speed of adjustment back to equilibrium. In the example, GFCF and imports were found to be cointegrated, and deviations from equilibrium were corrected at 37.5% per time period. Always remember to use EG critical values (not standard t-tables) when testing cointegration.
🧠 Quick Revision Questions
- What is the fundamental difference between using differencing versus cointegration when dealing with non-stationary time series?
- List the three conditions that must be satisfied for two time series to be cointegrated.
- What is the Granger Representation Theorem and what does it imply about cointegrated variables?
- In the Error Correction Model ∆Yₜ = β∆Xₜ + ρ(Yₜ₋₁ − γXₜ₋₁) + εₜ, what do each of the parameters β, ρ, and γ represent economically?
- Why can't we use standard t-distribution critical values when testing for cointegration using the Engle-Granger method, and what critical values should be used instead?
📘 Lecture 45 — Time Series, Cointegration and Error Correction-III
📖 Overview: This lecture continues the discussion of time series econometrics, focusing on autoregressive processes, vector autoregressive (VAR) models, ARIMA modeling, and cointegration testing. It provides practical Stata applications for estimating these models and interpreting their results, which is essential for analyzing economic data that is recorded over time.
🗂️ Topics Covered
The lecture covers Autoregressive (AR) processes including AR(p) and AR(1) specifications with Stata examples, Vector Autoregressive (VAR) models and stationarity requirements using Dickey-Fuller tests and Schwert's rule of thumb for optimal lag selection, ARMA and ARIMA modeling with post-estimation diagnostics, Johansen's test for cointegration using maximum likelihood estimation, and the Vector Error Correction Model (VECM) as a multivariate extension of ECM.
📝 Lecture Summary
Time Series Definition
Variables recorded over time can be observed at different frequencies: Annually (Macro data), Biannually (financial data), Quarterly (Macro data, agricultural data), Monthly (agricultural data, market prices), or Daily (Stock exchange, Foreign Exchange Rates, commodity prices). The lecture includes an example graph showing Pakistan's exports over time.
Autoregressive Process
An Autoregressive Process occurs when a variable depends linearly on its own past values (lags), expressed as a weighted sum of past values.
🔑 Definition — AR(p) process: 푦ₜ = φ₀ + φ₁푦ₜ₋₁ + φ₂푦ₜ₋₂ + ... + φₚ푦ₜ₋ₚ + εₜ
🔑 Definition — AR(1) process: 푦ₜ = φ₀ + φ₁푦ₜ₋₁ + εₜ
📌 Example — Stata AR(3) model: reg gdp L.gdp L2.gdp L3.gdp
VAR (Vector Autoregressive Model)
A VAR (Vector Autoregressive Model) is a multivariate time-series regression of each dependent variable on lags of itself and on lags of all the other dependent variables.
🔑 Definition — VAR(1) process for y and z:
- 푦ₜ = α₀ + α₁푦ₜ₋₁ + α₂푧ₜ₋₁ + uₜ
- 푧ₜ = β₀ + β₁푦ₜ₋₁ + β₂푧ₜ₋₁ + vₜ
📌 Example — Stata VAR(1) model: tsset time then var gdp exports, lags(1). If lags are not specified, 2 is the default.
Stationarity Requirement: For VAR, both series should be stationary. The Dickey Fuller test can be used to determine at what level data is stationary. For Dickey Fuller test, we need to know the appropriate lag.
Lag Selection Trade-offs:
- If p is too small, remaining serial correlation in the errors will bias the test.
- If p is too large, the power of the test will suffer.
- Monte Carlo experiments suggest it is better to err on the side of including too many lags.
📐 Schwert's (1989) rule of thumb: pₘₐₓ = [12 · (T/100)^(1/4)] where T = number of observations and [ ] means integer part.
📌 Example: In ECM.dta with 30 observations, lags = 8. The default lag length for the dfuller command is zero.
📌 Example — Stationarity test results: Imports are stationary at second level. The command dfuller for random walk with drift is used. If they follow random walk with drift, exports and imports are integrated of order 1.
Applying VAR
First determine the optimal lag length for VAR. The command is varsoc (number of max lags can be given).
🔑 Definition — AIC (Akaike Information Criterion): Should be minimized; suggested lag is ONE.
📌 Example — Model estimation: Default lag=2 so we need to specify ONE (suggested by AIC). Here the sign and significance, not the magnitude, are important.
Post Estimation Test: Stability of the model requires eigenvalues should be less than one (roots of the companion matrix). After running the model, use varstable, graph.
ARMA (Autoregressive Moving Average) and ARIMA (Autoregressive Integrated Moving Average)
An ARIMA model is a combination of AR and MA processes where AR is autoregressive, I is Integrated, and MA is a Moving Average process (a process containing past realizations of the variable's own residual).
🔑 Definition — ARMA(p,q) process: yₜ = φ₀ + εₜ + φ₁eₜ₋₁ + φ₂eₜ₋₂ + ... + φₚeₜ₋₉
- ARMA(1,0) is same as AR(1)
- ARMA(0,1) is same as MA(1)
📐 ARMA(1,1) process: yₜ = c + α₁yₜ₋₁ + β₁εₜ₋₁ + εₜ
Series where I=0 is stationary. arima is a maximum likelihood estimation (not OLS). The lecture discusses Univariate ARIMA.
📌 Example — Stata: Must run arima on a stationary series. Stationary level must be determined. Command: arima gdp, arima (1,1,1) which is the same as arima gdp, ar(1) ma(1).
ARIMA Post Estimation Commands in Stata:
estat acplotestimates autocorrelation and covariances (produces parametric autocorrelations with 95% confidence intervals)estat arootschecks the stability conditionsestat vcegives the Variance covariance matrix of the estimates
Johansen's Test for Cointegration
This test is based on maximum likelihood estimation and two statistics: maximum eigenvalues and a trace-statistic.
🔑 Definition — Johansen's Test: Used to test for cointegration among variables.
📌 Example — Stata command: vecrank exports imports, lags(1) using one lag as suggested by varsoc for VAR model. Results: Variables are cointegrated. If rank would have been zero, there would have been no cointegration.
Vector Error Correction Model (VECM)
ECM cannot be used in complex situations like with more nonstationary variables. A Vector Error Correction Model (VECM) adds error correction features to a multi-factor model such as a vector autoregressive model. It is the multivariate specification of ECM.
📌 Example — Stata: The command is vec. There is one lag less than that of VAR, but Stata will automatically subtract the lag. Syntax: vec varlist [if] [in] [, options]. Menu path: Statistics > Multivariate time series > Vector error-correction model (VECM).
📌 Example — Using the option alpha gives the short run adjustment parameters. Results show that gfcf responds faster than exports in case of changes or shocks.
Post Estimation commands for vec:
- Eigenvalues should be within the circle (stability check)
veclmartests the autocorrelation of residuals — in the example, no autocorrelation is detected.
⭐ Key Takeaways
The lecture teaches that autoregressive processes model variables based on their own past values, and when moving to multivariate settings, VAR models require all series to be stationary, with lag selection being critical—Schwert's rule helps determine optimal lags for Dickey-Fuller tests. ARIMA models combine autoregressive, integrated, and moving average components and require maximum likelihood estimation on stationary series. Johansen's test using maximum eigenvalues and trace statistics determines cointegration, and if variables are cointegrated, a VECM is the appropriate multivariate specification that automatically handles lag adjustments. Post-estimation diagnostics including stability checks (eigenvalues less than one) and autocorrelation tests (veclmar) are essential for model validation.
🧠 Quick Revision Questions
- What is the difference between an AR(p) process and a VAR(1) process?
- Why must both series be stationary before estimating a VAR model, and how is stationarity tested?
- What does Schwert's rule of thumb calculate, and why is choosing the correct lag important in Dickey-Fuller tests?
- What are the two statistics used in Johansen's test for cointegration, and what does the rank indicate?
- How does a Vector Error Correction Model (VECM) differ from a standard ECM, and what post-estimation commands are used to validate it?