School of Earth and Environment

Introduction to Input-Output Analysis using Matlab

Author: Anne Owen, University of Leeds

Data assistance: Arturo Andersen Chinbuah, University of Leeds

The general structure of an input-output table is:

 

 

Consider this very simple model of the economy:

Input-output analysis can be used to find out what the effect would be of an increase in the demand for agriculture from 12 to 16. If we demand more agriculture, not only does the output of agriculture have to increase, but also the all of the inputs into the supply chain of a product of agriculture. This will also generate an increase in emissions.

What we need is an equation that shows output as a function of final demand. Or rather \(\mathbf{x} = \mathbf{f(y)}\). This would allow us to see what happens to \(\mathbf{x}\) if \(\mathbf{y}\) increases. The following exercise uses Matlab to generate work through the Leontief equation used in input-output analysis.

1.  Loading the variables

1.1     Save the file 'prac 1 data.mat' to your own personal file system

1.2         In Matlab use the command

>> uiopen

and find this file from your file system. Notice that this file is a collection of matrices \(\mathbf{Z, y, v}\), and \(\mathbf{f}\) that you can now see in the Workspace.

1.3         Double click on \(\mathbf{Z}\) this opens the variable in the variable window. You can see that this is the transactions matrix in the example above. 

1.4         Generate the column vector of total output \(\mathbf{x}\) by:

>> x = sum(Z,2) + y

1.5         Verify that this is the same as the column sum of \(\mathbf{Z}\), added to \(\mathbf{v}\) 

>> x = sum(Z,1) + v

Usually, we take \(\mathbf{x}\) to be the row sum of \(\mathbf{Z}\) plus the final demand matrix. Occasionally IO tables do not balance and this sum is more accurate! Repeat

>> x = sum(Z,2) + y

to ensure that \(\mathbf{x}\) is a column vector.

2.  Calculating the total requirements matrix A

The total output \(\mathbf{(x_i)}\) of a particular sector can be expressed as:

$$ \mathbf{x_i} = \mathbf{z_{i1}} + \mathbf{z_{i2}} + \cdots + \mathbf{z_{ij}} + \mathbf{y_{i}} \label{Eq1}\tag{1} $$

Total output of a sector is a product of its intermediate and final demand.

If each element, \(\mathbf{z_{ij}}\), along row \(i\) is divided by the output \(\mathbf{x_j}\), associated with the corresponding column \(j\), then each element in \(\mathbf{Z}\) can be replaced with:

$$ \mathbf{a_{ij}} = \frac{\mathbf{z_{ij}}}{\mathbf{x_j}} $$

This new matrix \(\mathbf{A}\) is the total requirements matrix and shows the contribution each element in the transaction matrix makes towards total output.

2.1     In Matlab this is:

>> A = Z./repmat(x',3,1)     

Each element in \(\mathbf{Z}\) is element-wise divided by the total and to do this we need to transpose total output and repeat it for 3 rows.

3.  Calculating the Leontief inverse matrix L

Now if

$$ \mathbf{a_{ij}} = \frac{\mathbf{z_{ij}}}{\mathbf{x_j}} $$

Then

$$ \mathbf{z_{ij}} = \mathbf{a_{ij}x_j} \label{Eq2}\tag{2}$$

Substituting for \(\ref{Eq2}\) in \(\ref{Eq1}\) gives

$$ \mathbf{x_i} = \mathbf{a_{i1}x_1} + \mathbf{a_{i2}x_2} + \cdots + \mathbf{a_{ij}x_j} + \mathbf{y_i} $$

Which, in matrix format is:

$$ \mathbf{x} = \mathbf{Ax} + \mathbf{y} $$

But we wanted an equation that has \(\mathbf{x}\) as a function of \(\mathbf{y}\). Given our new knowledge of matrix algebra, we can rearrange this equation to make\(\mathbf{x}\) the subject of the equation:

$$ \mathbf{y} = \mathbf{x} - \mathbf{Ax} $$

$$ \mathbf{y} = \mathbf{x}(\mathbb{1} - \mathbf{A}) $$

$$ \mathbf{x} = (\mathbb{1} - \mathbf{A})^{-1}\mathbf{y} $$

$$ \mathbf{x} = \mathbf{Ly} $$

This is known as Leontief’s equation and \(\mathbf{L} = (\mathbb{1}-\mathbf{A})^{-1}\).

3.1     In Matlab

>> L = inv(eye(3)-A)

Check that \(\mathbf{x} = \mathbf{Ly}\)

>> L*y     

Do you get \(\mathbf{x}\)?

4.  Using the Leontief inverse to investigate a change in demand

So if demand for agriculture increases from 12 to 16, what happens to total output?

4.1     In Matlab,

This is your new final demand vector:

>> y2 = y+[4;0;0]

This is the resulting new output vector:

>> x2 = L*y2           

This shows how each sector has had to increase output as a result of an increase in final demand for a single sector:

>> x2-x                

5.  Using the Leontief inverse to investigate consumption based emissions

5.1     In Matlab find the total sum of the emissions

>> sum(f,2)

Now, if we find the emissions intensity, that is the emissions per unit of output, this is \(\mathbf{e} = \mathbf{fx^{-1}}\).

5.2     Note that

>> e = f*inv(x)        

gives an error because we can only find the inverse of a square matrix. To get round this, we turn  into a diagonal matrix. Try:

>> e = f*inv(diag(x))

Now multiplying both sides of (3) by \(\mathbf{e} = \mathbf{fx^{-1}}\) gives

$$ \mathbf{fx^{-1}x} = \mathbf{fx^{-1}Ly} $$

$$ \mathbf{f} = \mathbf{eLy} $$

Meaning that total emissions can be calculated by multiplying emissions intensity by the Leontief inverse and the vector of final demand!

5.3     Check that \(\mathbf{eLy}\) gives the same answer you found in 5.1

>> e*L*y

Now, rather than get a scalar result, we can use the ‘diag’ function in Matlab to disaggregate total emissions and find out further information

5.4     In Matlab, try:

>> F = diag(e)*L*diag(y)

If we sum the columns, this gives the full supply chain emissions associated with products

>> sum(F,1)

And the row sum is the original emissions associated with industry, \(\mathbf{f}\).

>> sum(F,2)

In this example, agriculture as an industry emits 72 tonnes of CO2. But agricultural products are only responsible for 48 tonnes (presumably agriculture gets used in the supply chain of other products). We can also see that emissions from the manufacturing industry accounts for 5 tonnes of the impact of an agricultural product.

5.5     Now see how emissions change when you use the new vector for final demand \(\mathbf{y2}\) instead of \(\mathbf{y}\). Repeat the steps in 5.4 to find \(\mathbf{F2}\), the \(\mathbf{F}\) matric of emissions associated with \(\mathbf{y2}\).

You should find an increase in overall emissions

>>  sum(sum(F2))

Emissions increase for each industry

>> sum(F2,2)

but only the emissions for agricultural products increase

>> sum(F2,1)

6.  Saving the variables

6.1     You have generated some additional data. Use the uisave command to save the additional variables \(\mathbf{A,L,F,e}\) and \(\mathbf{x}\). Make sure that you save the file to your own personal file system and clear the workspace

>> uisave({'A','F','L','Z','e','f','v','x','y','y2','F2'},'prac 1 data finish.mat') 

>> clear all 

7.  Multiregional Input-Output tables and Structure Arrays

In order to understand the role of trade in global emissions, we use a multiregional input-output table. Below is an example of an MRIO table with 3 regions.

 

 

7.1     Save the file ‘UK_MRIO.mat’ to your own personal file system

In Matlab use the command

>> uiopen

and find this file from your file system. Notice that this file is a <1x1 struct> in the Workspace window.

Double click on the ‘UK_MRIO’ array and look at the Variable window.  A structure array (or struct)  is an array with named fields that can contain data of varying types and sizes. ‘UK_MRIO’ contains:

·       \(\mathbf{Z}\) – 14x14 matrix

·       \(\mathbf{y}\) – 14x2 matrix

·       \(\mathbf{v}\)  – 1x14 vector

·       \(\mathbf{f}\) – 1x14 vector

These should be fairly familiar to you now. To access the emissions vector, we use the command.

 >> UK_MRIO.f

7.2     Structs are useful because they can also contain other additional metadata about the MRIO datafiles. For example, to find out the year that the data is for, type:

>> UK_MRIO.year

7.3     The UK_MRIO struct is also a struct of structs! Type:

>> UK_MRIO.Z_vert

This tells us that Z_vert contains information on the units and labels for the vertical columns of the \(\mathbf{Z}\) matrix. Try:

>> UK_MRIO.Z_vert(4)

This tells us that the 4th column of the Z matrix is ‘UK power, water and waste’ and that the units are millions of pounds.

7.4     To see all the labels, try:

>> UK_MRIO.Z_vert.label

7.5     This is what the complete MRIO database looks like:

7.6     Create the variable  and add it to your UK_MRIO struct by typing the following:

>> x = sum(UK_MRIO.Z,2)+sum(UK_MRIO.y,2)

>> UK_MRIO.x = x

7.7     Generate the metadata file for We are going to tell matlab to use the labels from the Z_vert struct:

>> x_vert = struct('unit', 'millions £', 'label', {UK_MRIO.Z_vert.label})'

7.8     Now add the x_vert struct to the main UK_MRIO struct:

>> UK_MRIO.x_vert = x_vert

7.9     Use the following code to generate \(\mathbf{e, A, L}\) and \(\mathbf{F_{UK}}\) which are the emissions intensity vector, the technical coefficients matrix, the Leontief inverse matrix and the emissions results matrix for the UK, respectively.

>> UK_MRIO.e = UK_MRIO.f*inv(diag(UK_MRIO.x))

>> UK_MRIO.A = UK_MRIO.Z./repmat(UK_MRIO.x',14,1)

>> UK_MRIO.L = inv(eye(14)- UK_MRIO.A)

 

>> UK_MRIO.F_UK = diag(UK_MRIO.e)* UK_MRIO.L*diag(UK_MRIO.y(:,1))

7.10   And we can add metadata variables using the following code:

>> UK_MRIO.e_horz = struct('unit', 'kg CO2 per £', 'label', {UK_MRIO.Z_horz.label})

>> UK_MRIO.A_horz = struct('unit', [], 'label', {UK_MRIO.Z_horz.label})

>> UK_MRIO.A_vert = struct('unit', [], 'label', {UK_MRIO.Z_vert.label})'

>> UK_MRIO.L_horz = struct('unit', [], 'label', {UK_MRIO.Z_horz.label})

>> UK_MRIO.L_vert = struct('unit', [], 'label', {UK_MRIO.Z_vert.label})'

>> UK_MRIO.F_UK_horz = struct('unit', 'Kilotonnes CO2', 'label', {UK_MRIO.Z_horz.label})

 

>> UK_MRIO.F_UK_vert = struct('unit', 'Kilotonnes CO2', 'label', {UK_MRIO.Z_vert.label})'

7.11   Open UK_MRIO.F_UK in the Variable Window. The results matrix shows:

Emissions generated in the UK to make UK final demand products consumed by UK consumers

Emissions generated in the UK to make RoW final demand products consumed by UK consumers

Emissions generated in the RoW to make UK final demand products consumed by UK consumers

Emissions generated in the RoW to make RoW final demand products consumed by UK consumers

 

7.12   The command

>> sum(sum(UK_MRIO.F_UK(1:7,1:7))) can be used to find the sum of emissions in the top left segment in the diagram above.

Solutions to this section can be found here, but try on your own first!

Fill in this table

 

UK consumption emissions, released in UK

UK consumption emissions, released in RoW

Total

 

 

7.13   The sum of the columns gives the emissions associated with the full supply chain of producing a product. The rows show each industry that was involved in making that product.

Fill in this table:

 

UK Agriculture & food product

RoW Agriculture & food product

UK Power product

RoW Power product

Total emissions (column sum)

 

 

 

 

Emissions from Power sectors (both UK and RoW)

 

 

 

 

% of footprint from Power sector

 

 

 

  

8              Making a simple bar chart

8.1     Remember, the carbon footprint of products consumed by UK consumers is the column sum of \(\mathbf{F_{UK}}\). Try:

 

>> sum(UK_MRIO.F_UK,1)

We can make a chart of this using the bar command

>> bar(sum(UK_MRIO.F_UK,1))

Matlab, usually makes a new window to display figures

8.2     Add a title and y axis label:

>> title('The UK footprint by product')

 

>> ylabel('Kilotonnes CO2')

8.3     Adding text labels to the x-axis is a little more complex. First we need to remove the numeric labels that are already there:

>> set(gca,'XTickLabel','')

Then set up a new text variable ‘t’ that has 14 x-coordinates and 14 y-coordinates and uses data from our struct Z_vert.label as the text.

>> t = text(1:14,1:14,{UK_MRIO.Z_vert.label});

Finally, we need to explain where to place the labels:

>> set(t,'HorizontalAlignment','right','VerticalAlignment','middle', 'Rotation',45)

If your labels go off the edge of the graph window, you can go to  >> Tools >> Edit Plot

From the graph menu and resize the plot area.

Search site