Filling a matrix with data from panel series
Posted: Wed Aug 02, 2017 1:30 am
Hi,
I'm trying to fill a matrix with data from a numeric series in panel format. I am fairly new at working with panel data in this manner so I do not know how to refer to the individual values within the panel series, specially because the dimension of the panel are (reporter, partner, trade_flow, comm_code, year)=(7,8,4,12,6).
The matrix contains reporters in the rows and partners in the columns. The idea is to compute a three years average of trade_value and fill the matrix with the corresponding cross-average for reporter/partner. I use group-by statitstics to compute the three year average (see below) as it needs to be by reporter-partner-tradeflow for all comm_codes in these groups .
series avg_all=@meansby(trade_value,reporter,partner,trade_flow,threeyears) ' three-years average of trade_values
Also, I am not completely sure whether I should be using a panel structure instead of a pool structure.
The other way I think this could be worked out is to move to a lower panel structure, where I only need partner, reporter and trade_flow with the values being the three year average of trade_values, so that I get rid of year and comm_code.
I attach the workfile and code for your inspection. Can you help please?
Thanks a lot in advance,
Marta
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
For !i=1 to m ' no. of reporters
For !j=1 to n ' no. of partners
' Not sure how to proceed from here
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
I'm trying to fill a matrix with data from a numeric series in panel format. I am fairly new at working with panel data in this manner so I do not know how to refer to the individual values within the panel series, specially because the dimension of the panel are (reporter, partner, trade_flow, comm_code, year)=(7,8,4,12,6).
The matrix contains reporters in the rows and partners in the columns. The idea is to compute a three years average of trade_value and fill the matrix with the corresponding cross-average for reporter/partner. I use group-by statitstics to compute the three year average (see below) as it needs to be by reporter-partner-tradeflow for all comm_codes in these groups .
series avg_all=@meansby(trade_value,reporter,partner,trade_flow,threeyears) ' three-years average of trade_values
Also, I am not completely sure whether I should be using a panel structure instead of a pool structure.
The other way I think this could be worked out is to move to a lower panel structure, where I only need partner, reporter and trade_flow with the values being the three year average of trade_values, so that I get rid of year and comm_code.
I attach the workfile and code for your inspection. Can you help please?
Thanks a lot in advance,
Marta
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
For !i=1 to m ' no. of reporters
For !j=1 to n ' no. of partners
' Not sure how to proceed from here
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