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
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 for Ordinary Least Squares
This video provides an example of Monte Carlo Simulation, using Ordinary Least Squares Estimators.
Check out http://oxbridge-tutor.co.uk/undergraduate-econometrics-course/ for course materials, and information regarding updates on each of the courses.
The Matlab code used in this simulation is shown below.
clear; close all; clc;
%Define the population parameters
alpha=1;
beta=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 variable randomly
x=4*randn(n,1);
%Generate errors in the population
e=randn(n,1);
%Generate the dependent variable
y=alpha+beta*x+e;
%Generate the LS estimates of alpha and beta using matrix formulation
X=[ones(n,1) x];
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) Check out https://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: https://ben-lambert.com/bayesian/ Accompanying this series, there will be a book: https://www.amazon.co.uk/gp/product/1473916364/ref=pe_3140701_247401851_em_1p_0_ti Monte Carlo Simulation for Ordinary Least Squares](https://i.ytimg.com/vi/BsCgwERndJ0/mqdefault.jpg)









