Uploaded November 2013 | Updated September 2026, 2 hours ago
This video provides an example of Monte Carlo Simulation, using Ordinary Least Squares Estimators.
Check out 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 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 Monte Carlo Simulation, using Ordinary Least Squares Estimators.
Check out 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 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










