

'pagestruct reporter @date(year) partner trade_flow comm_code

' Vectors containing unique values in ID series

svector svrep=@uniquevals(reporter)
svector svpar=@uniquevals(partner) 
svector svflow=@uniquevals(trade_flow)

vector vyear=@uniquevals(year)
vector vcomm=@uniquevals(comm_code)


' 1. Three year average of  Exports and Imports by Trade-Reporter pairs

' Create a matrix with rows = reporter, columns= partners, values = 3-y avg.
	scalar m=@rows(svrep)
	scalar n=@rows(svpar)

	string strrep=@wjoin(svrep)
	string strpar=@wjoin(svpar)

	matrix(m,n) avg
	avg.setrowlabels {strrep} 
	avg.setcollabels	{strpar}

	smpl @last-2 @last
	series threeyears = @recode(year=@last(year),year,@last(year)) ' Last three years available 

' Not sure how to proceed from here
	smpl @all
	series threeyears=@recode(threeyears=na,0,threeyears) 
	
	series avg_all=@meansby(trade_value,reporter,partner,trade_flow,threeyears) ' three-years average of trade_values
	
'-------------------------------------------------------------------------------

For !i=1 to m '  no. of reporters

	For !j=1 to n '  no. of partners

		if threeyears=2016 then

			smpl If reporter="ITA" and partner="DEU" and trade_flow="import" and comm_code=9  'then
			avg(!i,!j)=avg_all

		endif

	Next

Next

