0% found this document useful (0 votes)
62 views63 pages

Part II Practical Sessions

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 63

Part II.

Practical Sessions

1
Part II. Contents

Computable General Equilibrium (CGE)


model,
 General Algebraic Modeling System (GAMS),
Basic Dynamic Stochastic General
Equilibrium (DSGE) model,
The New Keynesian DSGE model (New
Neo-Classical Synthesis),

2
2.1 Computable General Equilibrium
(CGE) model
 Reading lists
 Lofgren et al., (2002) A Standard Computable
General Equilibrium (CGE) Model in GAMS

3
INTRODUCTION
 Over the past 25 years, computable general equilibrium (CGE)
models have become a standard tool of empirical economic
analysis.
 In recent years, improvements in model specification, data availability, and
computer technology have improved the payoffs and reduced the costs of
policy analysis based on CGE models, paving the way for their widespread
use by policy analysts throughout the world.
 It spans from:
 a static, “standard” CGE model
 A dynamic CGE model
 Recursive CGE model
 In most applications, the markets and prices in the model represent
actual markets with money used as a medium of exchange.
 However, especially in household models, they may be viewed as ‘implicit’
markets where the solution wages and prices represent ‘shadow prices’ or
exchange values. 4
What is a CGE model?
 Computable: Numerical solution – empirical data
General: Description of the whole economy
 Full economic cycle
 All markets (including factor markets)
 Equilibrium: Demand equals supply in all markets
 All markets are in equilibrium in benchmark -- by
assumption!
 After a shock (tax, demand, supply) in one or more
markets, prices adjust to achieve new equilibrium
 All prices adjust on all markets simultaneously
 Model
 Solvable set of simultaneous equations
 Empirical data
 Benchmark is Social Accounting Matrix (SAM), based on
I-O table. 5
CGE framework

spending on goods and services


Savings
Investments
goods and services

Households Firms

FDI

exports
imports

Factors of production

Factor incomes

REST OF THE WORLD

6
A Typology of CGE Modeling

Static: regions, sectors, factors,


economic agents Micro-Simulation
+ set of economic behaviors & Models:
relationships representative
agents hypothesis
“removed”

Dynamic=Static features
+ explicit inter-temporal features

7
What is a CGE model?
 Example of SAM for CGE
Firm Household Government Investment Total
(received)

Firm A C GF I A+C+GF+I

Household W GH W+GH

Government TF TH TF+TH

Investment SH SG SH+SG

Total A+W+TF C+TH+SH GF+GH+SG I


(expended)

A = intermediate inputs, C = consumption, W = wages, T = taxes, S = savings, I =


investment, G = government expenditures.

8
CGE model cont’d
The demand and supply responses of agents to
price changes are described by functions.
 Different types of demand and supply functions: Leontief,
Cobb-Douglas, Constant Elasticity of Substitution (CES), etc.

Fix location: benchmark quantities


land Fix slope: benchmark relative prices
Fix curvature: choose elasticity

labour

9
CGE model cont’d
Design issues:
 Sectoral aggregation: “agriculture” or
“wheat”, “potatoes”, “sheep”, etc.
 Regional aggregation: one region, multiple
regions, global.
 Comparative static (e.g. climate change
impacts in 2050 against BAU 2050) or dynamic
(climate change impacts against baseline
growth path)?
 What kind of dynamics: myopic, forward–
looking?
10
Standard CGE Model elements
 Input Output Economics & SAMs
 Behavioural Relationships/ Agents
– Supply
– Demand
– Trade
 Government
 Pricing and Imperfect substitutes
 Policy – tax equivalents
 Closure
– Accounting identities
– Endogenous/exogenous variables
– Macroeconomic assumptions
– Exchange rate determination
 Solution
– Equilibrium
– Linearization
– Per cent change variables

11
CGE Standard Model elements cont’d
Calibration/Benchmarking
Aggregation
– Agents
– Goods/Sectors
Experiments
– Welfare Measures
– Projections
– What if
Extensions
– Imperfect Competition, IRS
– Product Differentiation
– Dynamics
Results Comparisons
12
Input-Output economics & SAMs

Production= Intermediates + Value Added


Production= Intermediate demand + Final
Demand
 Macroeconomic accounting identities to
capture income flows, tax incidence, trade and
payments, and savings-investment balances.

 = > SAMs capture `circular flow’ of income


and expenditure

13
Input-Output economics & SAMs

spending on goods and services


Savings
Investments
goods and services

Households Firms

FDI

exports
imports

Factors of production

Factor incomes

REST OF THE WORLD

14
Input-Output economics & SAMs
 Whether neoclassical, strucuralist, neo-
Keynesian, or Monetarist, a CGE modeler must
respect accounting identities and equilibrium
conditions.
Hence, most applied work is based on a social
accounting matrix to benchmark (calibrate) a
model and to represent relevant accounting
identities.
 SAMs capture equilibrium conditions.
 Walras’ law applies.
15
Decision Making and Institutions

 Linkages in SAMs are accounted for by


modelling the decision-making process of the
firm, the consumer, as well as other economic
agents and institutions: production and
demand structure.
Trade results from that decision-making
processes and their interaction with
institutions:
 Production- Exports + Imports = Consumption

16
Closing the Model
 Need to define a numéraire (walras law allows
to “drop” one market).
 Assumption about the adjustment mechanism
in factor and commodity markets.
 Macro closure
– Macro accounting balance (gv’t expenditure and
deficit; aggregate saving and investment; balance
of trade and real- exchange rate).
– Macro adjustment mechanism (exogenously
determined).

17
Closing the Model
 Johansen closure: investment is exogenous and
consumption is the adjustment variable.
 Keynesian closure: nominal wage is fixed and
employment is the adjustment variable
(unemployment).
Kaldorian closure: wages could be less or equal to the
marginal product of labor (exploitation of labor model).
Classical closure: prices and wages are the adjustment
variables (constant employment) and investment
becomes endogenous and adjusts to total savings
available.
Foreign borrowing (Robinson): trade balance is
endogenous, current account and hence net capital
inflows are the adjustment variable.
18
2.2 General Algebraic Modeling System
(GAMS)
 GAMS is a software package used to solve systems of equations.
 GAMS stands for General Algebraic Modelling System and is constructed by the GAMS
Development Corporation.
 GAMS contains different solvers for different purposes.
 Various kinds of economic models can be written down as a system of equations,
including systems analysis, non-linear optimisation and equilibrium modelling.
 GAMS is widely used across the world among economists.
 Advantages:
– Admits all problem types (Linear Programing (LP), Integer Programing (IP), Non-Linear
Programming (NLP), Mixed Integer Linear Programing (MILP), Mixed Integer Non-linear programing
(MINLP))
– Interfaces with a variety of solvers
– Can express models compactly and symbolically
– Data and models are stored separately
 Disadvantages:
– Overhead slows execution
– Cumbersome to do scientific computations for preparing input data or for post-processing
optimization results.

19
WHY PREFER GAMS?
 Optimization models can be solved also in
popular environments such as Excel,
Mathematica, Matlab, Maple, etc.
 However, GAMS is superior when it comes to
large-scale models.
 GAMS does not implement solvers, rather than it
interfaces with the best freely- or commercially-
available ones.
 You can easily try various applicable solvers and find
what works best for your problem.

20
HOW DOES GAMS WORK?
 The user creates a text file in GAMS-readable format (a Windows editor
interface is available).
 This file is saved with the extension .gms and can be provided as input
to the GAMS software.
 GAMS compiles and executes, providing
– output to console
– output to file(s), as instructed by the user
– a default file with extension .lst providing record of the run, including
optimal solution values and any possible compilation or runtime errors.
 GAMS is available:
 Download a free demo version for your personal computer:
http://www.gams.com/download/
 All functions are available
 No time expiration
 Has limits on model size, but should be sufficient for homework
assignment.

21
Working with GAMS-IDE
 Most users of GAMS can run the system in the Integrated Development
Environment (IDE).
 When GAMS-IDE is started, a window will appear with a menu bar along the
top and a main Edit Window for GAMS applications.
 Input and output operations are controlled by the File pull down menu, with
other menu items used in edit operations, and in running the GAMS system.
 Users should begin each session by selecting a "project".
 A project is a system file you save but never have to touch.
 Still, its location is important because the folder (directory) of the current
project file is where (.gms) input and (.lst) output files are saved by default.
 This allows you to easily keep all the input and output files for any task
together in the same directory.
 Use different directories for different projects.
 The starting project file (if any) is shown at the top of the main GAMS
window; in the picture below, the starting project file is “W:\WRK\GAMS\my
project.gpr”.
 To select another, or create a new one, use the Project item on the File menu.

22
GAMS-IDE without any open files looks
as follows

23
The general structure of GAMS programs
 The first step in modelling in GAMS is to write an input file.
 Normally a GAMS input file has a file-extension .gms.
 You write the input file, run the model in GAMS and look at the output file
for the results (the output file has an extension .lst).
 The general structure of a simple GAMS input file contains the following
elements:
 PARAMETERS: gives the data or exogenous constants of the model; these values
are fixed.
 VARIABLES: indicates the variables that will be determined (calculated) within
the model.
 EQUATIONS: first, the equations have to be declared, then they are defined.
 MODEL: the model is given a name.
 SOLVE : the solution mode is specified, as well as a declaration whether the
optimand should be maximised or minimised.
 Each of these elements can exist more than once in a single GAMS model.
 The restrictions and special meanings of these words are all together called
the syntax of a model.
 GAMS is a computer package and will only understand what you want if you
write your model in the correct syntax.
24
MODELING IN GAMS

MODELS

25
MODELING IN GAMS

MODELS

26
Basics in GAMS coding
 Comment:
 Any line starting with * constitutes a comment and is not
interpreted by the GAMS parser.
 eg. GAMS code
* This is a comment
GAMS code
 End of line commenting is also possible via the following
declaration:
$eolcom ##
GAMS code ## This is a comment
 Larger blocks of the file can become comments as follows
$ontext
everything here are comments
…..
$offtext

27
SETS
 Sets are representative of indices in the vectors or
matrices used in the problem formulation.
 Syntax:
Set set_name comments /element_1, element_2, … ,
element_n /;

Examples:
Set MATH_COURSES courses available / DiffEq, Prob, LinAlg /;
Set COLORS the set of colors / Yellow, Green, Blue, Orange, Red/;

28
SETS cont’d
 Often useful to abbreviate the elements of a set:
Set i tasks / i1, i2, i3, i4, i5, i6, i7, i8 /;
 When you have a successive number of elements like above can
further reduce to:
Set i tasks / i1*i8 /;
 (GAMS will expand this as above)

29
DATA
 Essential to any problem is the data
 Different types of data types are defined based on the dimensionality they are
commonly used for:

Data Type Dimension


Scalar 0
Parameter 1
Table 2

 Parameter and Table are in fact generic keywords (can be used with any
dimensionality).
 SCALARS
 A scalar is a fixed parameter (a constant), and has no association with any set.
 Syntax:
Scalar scalar_name comments / scalar_value /;
 Examples:
Scalar Pi the value of “pi” / 3.15 /;
Scalar Life financial lifetime of productive units / 20 /;
Scalar Balance amount of money in my bank account as of 11/10 /18530/;
30
PARAMETERS
A parameter defines a vector and is associated
with a set.
Syntax:
Parameter parameter_name(set_name) comments /
element_1 value_1, element_2 value_2, … , element_n
value_n /;
 Example:
Set DOGS dogs in race / dog1*dog5 /;
Parameter ODDS(DOGS) probability of dogs winning / dog1 0.20,
dog2 0.25, dog3 0.00, dog4 0.30, dog5 0.25 /;

31
TABLES
Table defines a matrix and is associated with two
sets.
Syntax for an n by m table:
Table table_name(setA_name, setB_name) comments
element_B_1 element_B_2 ... element_B_m
element_A_1 value_1_1 value_1_2 ... value_1_m

element_A_2 value_2_1 value_2_2 ... Value_2_m

... ... ... ...

element_A_n value_n_1 value_n_2 ... value_n_m ;

Don’t forget the semicolon


32 !
TABLES
 Example:
Set DOGS dogs in race / dog1*dog5 /;
Set RACES races being run / race1*race3 /;
Table ODDS(DOGS, RACES) probability of dogs winning each race

race1 race2 race3


dog1 0.20 0.10 0.30
dog2 0.25 0.08 0.19
dog3 0.00 0.12 0.20
dog4 0.30 0.40 0.30
dog5 0.25 0.30 0.01 ;

33
DATA
Declaration, definition of data can occur
separately
Redefinition of data is also possible
If no definition is provided, the value of 0.0 is
given by default
• Example:
Scalar a /50/;
Scalar b; b = 50; b = 60;
Set i /i1*i3/;
Parameter c(i); c(‘i1’) = 1; c(‘i2’) = 2; c(‘i3’) = 3;
34
VARIABLES
Variables can be declared either as scalars (0-
dimensional) or over sets (multi-dimensional)
 Syntax:
variable_type Variable variable_name comments ;
variable_type Variable variable_name(set_name) comments ;

Declared type Type Values allowed


Free Continuous -inf to +inf
Positive Continuous 0.0 to +inf
Negative Continuous -inf to 0.0
Binary Discrete 0, 1
Integer Discrete Any integer

35
VARIABLES
Examples:
Free Variable z objective function ;

Set i some index / i1, i2, i3 /;

Positive Variable x(i) problem variables ;

36
VARIABLES
Each variable is a collection of 4 attributes
Attribute Access Symbol Before solution After solution
Level .l User can Solver reports
initialize solver optimal solution
Lower bound .lo User can set No change
lower bound (solver does not
use this)
Upper bound .up User can set No change
upper bound (solver does not
use this)
Margin .m No use Solver may
report solution
sensitivity

37
VARIABLES
Once declared, user may change these
attributes
Example:
Positive Variable x some variable ;
x.lo = 5; x.up = 10;
Set i some set /i1*i5/;
Positive Variable y(i) some other variables ;
y.lo(i) = 5; y.up(i) = 10;
y.lo(‘i3’) = 4; y.up(‘i3’) = 12;
y.lo(‘i5’) = 2; y.up(‘i5’) = 2; ## also, y.fx(‘i5’) = 2;

38
EQUATIONS
Equations make use of declared data and variables
to symbolically define the formulation’s constraints
(including the “z = obj. function” and constraint).
 Syntax (declaration):
Equation equation_name comments ;
Equation equation_name(set_name) comments ;
Equation equation_name(setA_name, setB_name) comments ;
 Syntax (definition):
equation_name.. G(var, data) =L= 0 ;
equation_name.. G(var, data) =E= 0 ;
equation_name.. G(var, data) =G= 0 ;
equation_name(set_name).. G(var, data, set_name) =L= 0 ;
equation_name(setA_name, setB_name)..
G(var, data, setA_name, setB_name) =L= 0 ;
where G is a function using GAMS function notation (see manual)
39
EQUATIONS
 Examples:
Equation objf ;

objf.. z =E= sum(i, p(i) * x(i));

Equation sumbound;

sumbound.. sum(i, x(i)) =L= card(i);

Equation constraint(i);

constraint(i).. q(i) * power(x(i), 2) =G= beta + gamma;

40
MODELS
 Once all relevant equations have been defined,
they can be bundled into a model object
(multiple models may exist in a single file)
Syntax:
Model model_name comments / all / ;
Model model_name comments / objf, sumbound, constraint / ;

All defined elements of


the array “constraint”

41
CALLING THE SOLVER!
 A model can now be passed to an applicable
solver
 Only solvers applicable for the particular model
type (LP, NLP, MIP, MINLP) may be selected.
 Multiple solvers may be applicable, so we need
to select the one we want.
 Syntax:
Option model_type = solver_name;
Solve model_name using model_type minimizing objV_name;

42
CALLING THE SOLVER!
 Examples:
Option LP = CPLEX;
Solve mymodel1 using LP minimizing z1;
Option NLP = CONOPT;
Solve mymodel2 using NLP maximizing z2;
Option MINLP = BARON;
Solve mymodel3 using MINLP minimizing z3;

43
DISPLAYING THE RESULTS
Solver progress and final result will be displayed
in console, but exact output will depend on
which solver was used.
 Optimization results will certainly be included
in the .lst file, though may be hard to find.
 Better provide a command to neatly display
optimization results.
At the end of .gms file, add the following:
 Display variable_name.l;

44
BELIEVING THE RESULTS
After the Solve statement is executed, the model
and solver return status numbers which are stored
in the model object
model_name.modelstat
model_name.solvestat
These numbers describe important properties of
the model and solver such as feasibility or
guarantees of optimality of the solution.
They are given in the listing file generated after
one attempts to solve a model (or can be
conveniently displayed via display).
What each number means can be found in the
GAMS manual. 45
A TOY EXAMPLE (TRANSPORTATION
PROBLEM)

*transportation costs are assumed to be $90 per case per kMile 46


OPEN GAMS

47
CREATE A PROJECT

48
CREATE .GMS FILE
• SETS
– Plants
– Markets

• SCALARS (0-D)
– Unit cost per kMile

• PARAMETERS (1-D)
– Plant capacities
– Market demands

• TABLES (2-D)
– Plant-to-market distances
– Cost per case
(= unit cost * distance)
49
CREATE .GMS FILE
• SETS
– Plants
– Markets

• SCALARS (0-D)
– Unit cost per kMile

• PARAMETERS (1-D)
– Plant capacities
– Market demands

• TABLES (2-D)
– Plant-to-market distances
– Cost per case
(= unit cost * distance)
50
CREATE .GMS FILE
• VARIABLES
– Quantities (2-D, positive)
– Obj. function value (0-D, free)

• EQUATIONS
– Objective definition (0-D)
– Don’t exceed plant capacities (1-D)
– Do meet market demands (1-D)

• MODEL
– All equations defined thus far

• CALL SOLVER
– Use LP solver

• DISPLAY OUTPUT
– ∗ and ∗ to be displayed in .lst file 51
RUN GAMS

52
RUN GAMS

53
RUN GAMS

54
RUN GAMS

55
ONLINE REFERENCES
• GAMS Model Library
http://www.gams.com/modlib/modlib.htm

• GAMS – A User's Guide


http://www.gams.com/dd/docs/bigdocs/GAMSU
sersGuide.pdf

• GAMS List Archive (Archived Answers to Most


Frequently Asked Questions)
http://www.gams.com/maillist/gams-l-
archive.pdf
56
EQUATIONS
• Frequent example:
Equation constraint(i);

constraint(i)$(ord(i) > 1).. x(i) =G= y(i-1);

Equation constraint_bound;

constraint_bound.. x(‘i1’) =G= y0;

Model mymodel /constraint, constraint_bound/;

Although all constraints added in the list, the model will only
include those constraints that were actually defined
57
ALIASES
 Sometimes it is convenient to define aliases for a particular set

 For example, consider the need to declare the constraints

 The following is erroneous


Set i / i1, i2, i3, i4 /;
Constraint(i) .. x(i) – sum(i, y(i)) =E= 0;

58
ALIASES
 Sometimes it is convenient to define aliases for a particular set
 For example, consider the need to declare the constraints

 One way to do this would be


Set i / i1, i2, i3, i4 /;
Set ip / i1, i2, i3, i4 /;
Constraint(i) .. x(i) – sum(ip, y(ip)) =E= 0;

 But this is cumbersome and prone to mistakes

59
ALIASES

 Sometimes it is convenient to define aliases for a particular set

 For example, consider the need to declare the constraints

 An alias statement introduces additional name(s) for the set


Set i / i1, i2, i3, i4 /;
alias(i, ip);
Constraint(i) .. x(i) – sum(ip, y(ip)) =E= 0;

60
PUT WRITING FACILITY
Output to console and to the listing file are
mostly predetermined (user has very little
control via some options).
 GAMS offers the ability for the user to create
customized output to some external text file.
 A number of put statements can be used to that
purpose.

61
PUT WRITING FACILITY

62
ONLINE REFERENCES
• GAMS Model Library
http://www.gams.com/modlib/modlib.htm

• GAMS – A User's Guide


http://www.gams.com/dd/docs/bigdocs/GAMSU
sersGuide.pdf

• GAMS List Archive (Archived Answers to Most


Frequently Asked Questions)
http://www.gams.com/maillist/gams-l-
archive.pdf
63

You might also like