$Title Mapping and Aggregating Input-Output table into GAMS *============================================================================= $ontext (1) This is the accompanying GAMS code for the note: Corong, Erwin (2007). "Aggregating Input-Output (IO) table in GAMS". Available at: www.pep-net.org Poverty and Economic Policy (PEP) Research Network. (2) This program/code greatly benefited from Jesper Jensen's lecture on aggregating input-output table using GAMS/GDX during his GAMS-MPS/GE training course. The codes used in this exercise is a modified version of the one presented during the training. (3) All errors herein remain my sole responsibility. (4) This program maps IO table data data from Excel to GAMS using GDX facility (5) Input-Output: The IO Table used here is hypothetical Erwin L. Corong Please send comments to erwincorong@gmail.com This code is freely distributed without any warranty. Users can share or modify it. However, it should not be used to misrepresent any person or institution stated herein. The usual disclaimer applies. April 2007 $offtext *============================================================================= *========================= Read data from excel ============================== $call gdxxrw IO_table.xls par=iodata rng=b6 *============================================================================= *======================= Defining a name for the data ======================== *Defining a name for the data parameter iodata(*,*) io data *============================================================================= *========================= CALLING AND LOADING GDX FILE ====================== *Specify the GDX file to be used for reading $gdxin IO_table.gdx *Read GAMS symbol from the GDX file. Note that the word "iodata" has been *declared above before the the $load command $load iodata display iodata; *============================================================================= *============================= SET DECLARATION =============================== *set definitions and maps set n numeric labels / 1*20 / set i sectors / AGRI Agriculture, Fishery and Forestry MNQG Mining and Quarrying MFNG Manufacturing CONs Construction EGWA Electricity, Gas and Water TRCS Transport and Communications WRTR Wholsale and Retail Trade FINA Finance REAL Real Estate PSER Private Services GSER Government Services / set fd final demands / PCE Personal Consumption Expenditure GGCE General Government Consumption Expenditure GFCF Gross Fixed Capital Formation CHST Changes in Stocks EXPO Exports IMPO Imports / set va value added / COMP Compensation DEPR Depreciation ITXN Indirect Taxes-Subsidies OPSU Operating Surplus / set mapi(n,i) mapping numeric labels to sectors / 1. AGRI 2. MNQG 3. MFNG 4. CONS 5. EGWA 6. TRCS 7. WRTR 8. FINA 9. REAL 10. PSER 11. GSER / set mapva(n,va) mapping numeric lables to value added / 13. COMP 14. DEPR 15. ITXN 16. OPSU / set mapfd(n,fd) mapping numeric lables to final demands / 13. PCE 14. GGCE 15. GFCF 16. CHST 17. EXPO 18. IMPO / ALIAS (m,n), (i,j); *============================================================================= *============================= Data Handling ================================= *============================= Data Handling ================================= *Extracting and labeling data parameter iod input-output demand vad value added demand fin final demand imptx import taxes; iod(i,j) = sum((n,m)$(mapi(n,i) and mapi(m,j)), iodata(n,m)); vad(va,i)= sum((n,m)$(mapva(n,va) and mapi(m,i)), iodata(n,m)); fin(i,fd)= sum((n,m)$(mapi(n,i) and mapfd(m,fd)),iodata(n,m)); imptx(va,fd) = sum((n,m)$(mapva(n,va) and mapfd(m,fd)),iodata(n,m)); display iod, vad, fin, imptx *==================== COLUMN AND ROW CONSISTENCY CHECK ===================== Parameter colchk check the column sums in the IO table colrow check the supply-demand balance in the IO table; *Check total cost of production colchk(i) = *Production sum(j,iod(j,i)) + sum(va,vad(va,i)) - *Less total output as reported in the IO table sum(mapi(n,i),iodata("18",n)); *Check the supply demand balance colrow(i) = *Total demand sum(j,iod(i,j)) + sum(fd,fin(i,fd)) *domestic supply - (sum(j,iod(j,i)) + sum(va,vad(va,i))); *============================================================================= *======================= SET DECLARATION FOR DATA AGGREGATION =============== *Aggregation sets (Maps) Set G sectoral classifications / AGR Agriculture MFG Manufacturing PSE Private Services UTI Utilies and transport and communications WTR Wholesale and Retail Trade OSE Other Services GSE Government or Public Services / Set Map(*,*) mapping individual industry to sectoral classifications / AGRI.AGR MNQG.MFG MFNG.MFG CONS.PSE EGWA.UTI TRCS.UTI WRTR.WTR FINA.PSE REAL.PSE PSER.PSE GSER.GSE / alias (g,gg); *============================================================================= *==================== Aggregating IO Table from 11x11 to 4x4 ================= parameter iodat aggregated inter-industry matrix vadat aggregated value added finde aggregated final demand imptax aggregated import tax-tariff ; iodat(g,gg) = sum((i,j)$(map(i,g) and map(j,gg)), iod(i,j)); vadat(va,g) = sum(i$map(i,g),vad(va,i)); finde(g,fd) = sum(i$map(i,g),fin(i,fd)); imptax(va,fd) = imptx(va,fd) ; DISPLAY iodat, vadat, finde, imptax *============================================================================= *==================== Flagging for empty row and columns ===================== *From Tom Rutherford (2005) set negval(*,*) Check for negative balance set empty(g,*) Check for empty rows and columns; negval(g,gg) = yes$(iod(g,gg)<0); empty(g,"row") = 1$(sum(gg,iod(g,gg))=0); empty(gg,"column") = 1$(sum(g,iod(g,gg))=0); display negval, empty; *============================================================================= *================= Unloading to Excel through GDX ============================ execute_unload 'io_table.gdx', iodat vadat finde imptax execute 'gdxxrw.exe io_table.gdx o=aggregated_IO.xls par=iodat rng=a1 par=vadat rng=a8 par=finde rng=j1 par=imptax rng=a14' *============================================================================= *=========================End of the GAMS Code ===============================