

' I. REAL EFFECTIVE EXCHANGE RATE (q)
'1. This loop computes the DOMESTIC product of prices and exchange rate
For !i=1 to @rows(sv_cc)
	%prd= "_prd_" + sv_cc(!i)
	%cpi= sv_cc(!i) + "_cpi"
	%e= sv_cc(!i) + "_e"
	series {%prd}=({%cpi}/100)*{%e} ' prd = CPI x Nominal Exchange rate
Next


'2. This loop computes the FOREIGN ratio of exports over imports

For !i=1 to @rows(w)
	%reer= "_reer_" + sv_cc(!i) ' _pr_ = reer
	%c = @trim(sv_cc(!i))
	series {%reer}= 1

	For !j=1 to @columns(w)
		If !i<>!j then
			If @eqna(@lower(%c),@lower("us")) or @eqna(@lower(%c),@lower("uk")) or @eqna(@lower(%c),@lower("jp")) or @eqna(@lower(%c),@lower("ca")) then 
			'If @lower(sv_cc(!i))=@lower("pp") then ' or @eqna(%c,"uk") or @eqna(%c,"jp") or @eqna(%c,"us"))  then
				%prfij= "_prf_" + sv_cc(!i)+sv_cc(!j) ' prfij = [(CPIxNER)i/(CPIxNER)j]^w(i,j), i = domestic, f= foreign
				%prd= "_prd_" + sv_cc(!i)
				%prf="_prd_" + sv_cc(!j)
			
				series {%prfij}=  ({%prd}/{%prf})^w(!i,!j)
				{%reer}={%reer}*{%prfij} ' Geometric average of non-eurozone countries
			else
			'If  (@neqna(%c,"ca") or @neqna(%c,"uk") or @neqna(%c,"jp") or @neqna(%c,"us"))  then	
				%prfij= "_prf_" + sv_cc(!i)+sv_cc(!j) 				
				%prd= "_prd_" + sv_cc(!i)		
				%prf="_prd_" + sv_cc(!j)		
				%gdpw=sv_cc(!i)+"_gdpw" ' GDP weight for eurozone countries in the model
				%prez="_prez_" + sv_cc(!i) 
				%prfijw= "_prfw_"+sv_cc(!i)

				series {%prez}=0
				series {%prfij}= (({%prd}/{%prf})^w(!i,!j))' For country i, it coumputes the same ratio than above for each of the EZ countries, and multiplies it by the gdp weight.
				series {%prfijw}={%prij}*{%gdpw} 
				series {%prez}={%prez}+prfijw ' Adds up the weithed ratio for EZ countries to construct a EZ aggregate.
			'endif
			'endif
			'delete {%prfij} 
		endif
		endif
	Next
		{%reer}={%reer}*{%prez}  'Multiplies the EZ component to the reer for non-EZ countries 
		'delete {%prez}
Next

