MATLAB: Augmented dicky-fuller with lags

adfadf with lagdicky fuller

I need to run the following code
function [estm]=ADF_FL(y,adflag,mflag)
t1=size(y,1)-1;
const=ones(t1,1);
trend=1:1:t1;
if mflag==1; tval=zeros(1,2*2+1); end;
if mflag==2; tval=zeros(1,3*2+1); end;
if mflag==3; tval=zeros(1,1*2+1); end;
y1 = y(size(y,1)-t1:size(y,1)-1);
dy = y(2:size(y,1)) - y(1:size(y,1)-1);
dy0 = dy(size(dy,1)-t1+1:size(dy,1));
x=y1;
if mflag==1; x=[x const]; end;
if mflag==2; x=[x const trend]; end;
if mflag==3; x=x; end;
When I start writing the code i get the error message:
Function definitions are not permitted in this context.
I am new to matlab and any help is appreciated.

Best Answer

You cannot type in a function definition at the command prompt, and you cannot include a function definition in a MATLAB script file.
You will need to save the above in a file named ADF_FL.m