Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Help with Econometrics Simulation

Subject: Help with Econometrics Simulation

From: Ricardo Silva

Date: 21 Nov, 2008 17:57:01

Message: 1 of 1

Hi, I wrote a code to replicate the original Dickey and Fuller critical values for Unit Root Tests. However, the number doesn't match. Any help with the code below?
Thanks,
Rick
%Critical Values for origial DF tests
clear
clc
format short
%DGP
rho=1; %AR coeff.
ct=0.5; %Constant
t0=50; %dropped observations
t1=150; %Sample Size
mc=1000; %MC replication
yg(1)=0; %Initial value
%Hip. Cofiguration (OLS2 fuction at the end )
%c=1 -- Only Constant
%c=2 -- Constant ans Trend
c=1;
%Begin the Monte Carlo Looping
for j=1:mc
    %Loop para o Processo Gerador de Dados
    for t=2:t1
        u(t)=normrnd(0,1);
        yg(t)=ct+rho*yg(t-1);
        mu=mean(yg);
        z(t)=(rho-1)*(yg(t-1)-mu)+u(t);
    end;
    %Drop Initial Observations
    w=z(t0:t1)';
    bigt=length(w);
    x=w(1:bigt-1);
    y=diff(w);
    %OLS Regression
    [tratio]=ols2(y,x,c); df_t=tratio(1);
    %Save t-values
    if j == 1;
        sto=df_t;
    else
        sto=[sto df_t];
    end;
end; %Fim do Monte Carlo
%Calculating Critical Values
sto=sto';
%Critical Values 1% 2.5% 5% 10% 90% 95% 99%
disp('1% 2.5% 5% 10% 90% 95% 99%')
disp(prctile(sto, [1 2.5 5 10 90 95 99]))


% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function [b,resid,vcv,tratio]=ols2(y,x,c)
% if c == 1;
% x=[x ones(rows(x),1)];
% end;
% if c == 2;
% x=[x ones(rows(x),1) seqa(1,1,rows(x))];
% end;
% df=rows(x)-cols(x);
% b=inv(x'*x)*x'*y;
% resid=y-x*b;
% sigsq=resid'*resid/df;
% vcv=sigsq*inv(x'*x);
% se=sqrt(diag(vcv));
% tratio=b./se;

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us