
' Open the workfil -> make sure you workfile is in the same folder as where you saved this program
wfopen .\inf_unem.wf1

' Vector to store the estimated rho's, so 100 is the number of iterations
vector(100) rho

' STEP1: Estimate the model
equation model0.ls inf c unem

' STEP 2: Get the residuals
model0.makeresids uhat1
' Estimate rho
equation rho_est1.ls uhat1 uhat1(-1)
' Store the first estimated rho in the vector
rho(1) = rho_est1.@coefs(1)

' STEP3: Generate the quasi-difference data
genr inf_adj		 	= inf 		- rho(1)*inf(-1)
genr unem_adj		= unem 	- rho(1)*unem(-1)

' Fix the first observation -> transform

' Generate the series where the quasi differenced data are stored + 1 observation
genr inf_adj_all		 = na
genr unem_adj_all	 = na

' The transformation of the first observation
smpl 1948 1948 
inf_adj_all 		 = (1-rho(1)^2)^(1/2)*inf
unem_adj_all	 = (1-rho(1)^2)^(1/2)*unem

' Import the all the other observation in the series
smpl 1949 1996
inf_adj_all			= inf_adj
unem_adj_all		= unem_adj
smpl @all

' Generate the constant for the transformed model
genr constant_adj = 1-rho(1)

' STEP 4: Estimate the model with the quasi-differenced data
equation model1.ls inf_adj_all constant_adj unem_adj_all

' STEP 5: Make new set of residuals 
model1.makeresids uhat2

' START ITERATION

for !n=2 to 100

' Estimate a new rho
equation rho_est{!n}.ls uhat{!n} uhat{!n}(-1)
'Store it in the vector
rho(!n) = rho_est{!n}.@coefs(1)

' Set quasi-differenced series back to "na"
inf_adj	 	= na
unem_adj	 = na
inf_adj_all	 	= na
unem_adj_all	 = na

' Generate the quasi-differenced data using the just estimated rho
genr inf_adj		 	= inf 		- rho(!n)*inf(-1)
genr unem_adj		= unem 	- rho(!n)*unem(-1)

' The transformation of the first observation
smpl 1948 1948 
inf_adj_all 		 = (1-rho(!n)^2)^(1/2)*inf
unem_adj_all	 = (1-rho(!n)^2)^(1/2)*unem

' Import the all the other observation in the series
smpl 1949 1996
inf_adj_all		= inf_adj
unem_adj_all	= unem_adj
smpl @all

' Set the constant
constant_adj = 1-rho(!n)

' Estimate the model with the quasi differenced data
equation model{!n}.ls inf_adj_all constant_adj unem_adj_all

!s = !n+1
model{!n}.makeresids uhat{!s}

' next iteration
next

