' operates on  "replicate_tfp_tables.wf1".
%path = @runpath
cd %path

'alpha cn   'country names (EZ only)
'cn(1) = "BE"
'cn(2) = "GER"
'cn(3) = "SPA"
'cn(4) = "FRA"
'cn(5) = "IRE"
'cn(6) = "ITA"
'cn(7) = "NET"
'cn(8) = "AUS"
'cn(9) = "FIN"
''cn(10) = "EZ"

matrix(11,6) coef1 ' declare a matrix for storing results

for !j=1 to 9

%x = cn(!j) ' pick a country name from cn vector

smpl if cntry = %x

equation reg2_{%x}_ar.ls lwa c lwa(-1) ' AR(1) regression, time-series (by country)
series res_ar2_{%x} = resid ' residuals

coef2(!j,1) = reg2_{%x}_ar.@coefs(2) ' fill matrix with coefficients

next

smpl @all if cntry="GER" or cntry="BE" or cntry="SPA" or cntry="FRA" or cntry="IRE" or cntry="ITA" or cntry="NET" or cntry="AUS" or cntry="FIN"  ' or c_id="EZ"

' create a group or residual series. Export them manually into matlab (no export function?)

group g2ar res_ar2_be res_ar2_ger res_ar2_spa res_ar2_fra res_ar2_ire res_ar2_ita res_ar2_net res_ar2_aus res_ar2_fin  '  res_ar_ez ' Traded


