Monte Carlo Simulation of Omitted Variable Bias in Least Squares @SpartacanUsuals
Monte Carlo Simulation of Omitted Variable Bias in Least Squares  @SpartacanUsuals
Uploaded November 2013 | Updated September 2026, 2 hours ago
This video provides an example of how Monte Carlo Simulation can be used to demonstrate the bias and inconsistency of Ordinary Least Squares in the presence of an omitted variable.

clear; close all; clc;



%Define the population parameters

alpha=1;

beta1=1;

beta2=1;



% Sample size n

n=10000;



% Number of samples m

m=1000;



% Store the estimated beta in a vector

beta_hat=zeros(m,1);





for i=1:m



%Generate independent variables randomly

x1=4*randn(n,1);

x2=0.25*x1+randn(n,1);



%Generate errors in the population

e=randn(n,1);





%Generate the dependent variable

y=alpha+beta1*x1+beta2*x2+e;



%Generate the LS estimates of alpha and beta using matrix formulation



X=[ones(n,1) x1];



beta_hatvec=(inv((X'*X)))*X'*y;



% Pull out only the second component - the estimate of beta



beta_hat(i)=beta_hatvec(2);

end





zoom=0.8;

% Draw a histogram of the result

FigHandle = figure('Position', [750, 300, 1049*zoom, 895*zoom]);

hist(beta_hat,20)

xlabel('Beta hat')

ylabel('Frequency')

xlim([0.5,1.5]) Check out ben-lambert.com/econometrics-course-problem-sets-and-data for course materials, and information regarding updates on each of the courses. Quite excitingly (for me at least), I am about to publish a whole series of new videos on Bayesian statistics on youtube. See here for information: ben-lambert.com/bayesian Accompanying this series, there will be a book: amazon.co.uk/gp/product/1473916364/ref=pe_3140701_247401851_em_1p_0_ti
Monte Carlo Simulation of Omitted Variable Bias in Least SquaresMonte Carlo Simulation for Ordinary Least SquaresHow to code up a bespoke probability density in StanMaximum likelihood estimation of factor analysis models - part 2Why we typically use dependent sampling to sample from the posteriorAn introduction to the Poisson distribution - 2Score test (Lagrange Multiplier test) - introductionRepresenting heteroscedasticity in matrix formWhat is meant by overfitting?Estimating the error variance in matrix form - part 1Bayesian posterior samplingAn introduction to Gibbs sampling
Ben Lambert |

Monte Carlo Simulation of Omitted Variable Bias in Least Squares

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER