How to build a recursive dynamic model

Problems with modeling
Post Reply
ZNSen
User
User
Posts: 9
Joined: 6 years ago

How to build a recursive dynamic model

Post by ZNSen »

Hi dear all,
I am writing a dynamic model but it is quite challenging for me since I´m a biginner in modelling. My objective is to build a dynamic Partial Equilibrium model to assess the implementation of some policies on agricultural commodity market. I have started with a simple model with a time path of 10 years from 2015 to 2025 with 2014 as basline. I´m trying unsuccessfully to include a recursive dynamic element (price expectation scheme) which is represented by this equation : pexp(Yr) = pexp(Yr-1,i) + 0.33*(price(Yr-1,i) - pexp(Yr-1,i)).
The "PEXP" should replace the variable "PRICE" in the calibration equation " int_supply(Yr,i) " and the supply equation "q_supply(Yr,i)"

My question is how can I insert this equation in the following model :

* Cereal market Model

Sets
Var variables
/ SUPPLY
DEMAND
NX
PRICE
PEXP
/

polpar policy parameter names
/
prodsub producer subsidy
conssub consumer subsidy
psupport price support
/

shiftpar shift parameters
/
tp technical progress
chg_dem change in demand
/

i products
/
maize, rice, sorghum
/
Yr year
/ 2014*2025/

Yrn0 time path /2015*2025/

res simulation results
/
SUPPLY
DEMAND
NX
PRICE
PEXP
* STOCK
/
;

Alias (i,j);

Parameters

el_supply(i,i) Price elasticity of supply
el_dem(i,i) Price elasticity of demand
int_supply(Yr,i) Supply intercept
int_dem(Yr,i) Demand intercept

tp(i) Rate of technical progress
chg_dem(i) Rate of change in demand
* STOCK(Yr,i) stock size

psupport(i) Price support
prodsub(i) Producer subsidy
conssub(i) Consumer subsidy
results(res,i,Yr)

pROW(i) PRICE IN REST OF THE WORD (F per t)


pROW(i)/
Maize 20000
Rice 25000
Sorghum 15000
/
;

Table policies( i, polpar) shifter parameters
psupport prodsub conssub
Maize 0 0 0
Rice 0 0 0
Sorghum 0 0 0
;

Table shifters( i, shiftpar) shifter parameters
tp chg_dem
Maize 0 0
rice 0 0
sorghum 0 0
;

Table basedata( Yr, i, Var) base data values
SUPPLY DEMAND PRICE PEXP
2014.maize 753121 741921 20000 22000
2014.rice 424315 1075834 25000 28000
2014.sorghum 154692 153572 15000 26000
;
Table supply_elas(i,j) supply elasticities
maize rice sorghum
Maize 0.98 -0.015 -0.01
Rice -0.017 0.2 -0.009
Sorghum -0.021 -0.017 0.3
;

Table demand_elas(i,j) demand elasticities
maize rice sorghum
Maize -0.634 0.02 0.04
Rice 0.08 -0.634 0.03
Sorghum 0.08 0.02 -0.75 ;

* assign parameter values:
tp(i) = shifters(i, 'tp');
chg_dem(i) = shifters(i, 'chg_dem');
el_supply(i, j) = supply_elas(i, j);
el_dem(i, j) = demand_elas(i, j);

* assign initial policy parameter values:
prodsub(i) = policies( i, 'prodsub');
conssub(i) = policies( i, 'conssub');
psupport(i) = policies( i, 'psupport');

Variables
SUPPLY(Yr, i) Supply of cereal at year Yr(tonne)
DEMAND(Yr, i) Demand of cereal at year Yr (tonne)
NX(Yr, i) Net exports of cereal at year Yr(tonne)
PRICE(Yr, i) price (f cfa per tonne)
PEXP(Yr, i) EXPECTED PRICE
* STOCK(Yr, i) stock size (tonne)

;

* here: start values for variables
SUPPLY.L(Yr,i) = basedata('2014',i, 'SUPPLY');
DEMAND.L(Yr,i) = basedata('2014',i, 'DEMAND');
NX.L(Yr,i) = SUPPLY.L('2014',i) - DEMAND.L(Yr,i);
PRICE.L(Yr,i) = basedata('2014',i, 'PRICE');

*STOCK.L(Yr,i) = basedata(Yr,i, 'STOCK');


* here: calibrate intercepts
int_supply(Yr,i) = SUPPLY.L(Yr,i)/prod(j, PRICE.L(Yr,j)**el_supply(i,j));
int_dem(Yr,i) = DEMAND.L(Yr,i)/prod(j, PRICE.L(Yr,j)**el_dem(i,j));

Equations
* Declaration of equations
q_dem(Yr,i) demand function
q_supply(Yr,i) supply function
q_nx(Yr,i) netto exports definition
q_Price(Yr,i) market balance
;

* here: define equations

q_supply(Yr,i)..
SUPPLY(Yr,i) =E= int_supply(Yr,i) * prod(j, (PRICE(Yr,j) + prodsub(j))**el_supply(i,j)) * (1+tp(i));

q_dem(Yr,i)..
DEMAND(Yr,i) =E= int_dem(Yr,i) * prod(j, (PRICE(Yr,j) - conssub(j))**el_dem(i,j)) * (1+chg_dem(i));

q_nx(Yr,i)..
NX(Yr,i) =E= SUPPLY(Yr,i) - DEMAND(Yr,i);

q_price(Yr,i)..
PRICE(Yr,i) =E= pROW(i) + psupport(i);

MODEL Benin /all/;


SUPPLY.L(Yr,i) = basedata('2014',i, 'SUPPLY');
DEMAND.L(Yr,i) = basedata('2014',i, 'DEMAND');
NX.L(Yr,i) = SUPPLY.L('2014',i) - DEMAND.L(Yr,i);
PRICE.L(Yr,i) = basedata('2014',i, 'PRICE');
PEXP.L(Yr,i) = basedata('2014',i, 'PEXP');

* solve model
SOLVE Benin using MCP ;
* store results
results('SUPPLY',i,Yr) = SUPPLY.L(Yr,i);
results('DEMAND',i,Yr) = DEMAND.L(Yr,i);
results('NX',i,Yr) = NX.L(Yr,i);
results('PRICE',i,Yr) = PRICE.L(Yr,i);

DISPLAY results;

****

Thanks for your help!
User avatar
Renger
Posts: 639
Joined: 7 years ago

Re: How to build a recursive dynamic model

Post by Renger »

Hi
I probably would write a loop and then update PEXP as a parameter instead of a variable(you then do not define your variables over the set year anymore, so your model is just for one year and solve every time in the year loop).

Some pseudo code:

Code: Select all

* initialize pexp for the first year
pexp_prev(i) = ...
pexp_r(i) = ...

loop(yr,
     pexp_prev = pexp_r(i);
    solve mymodel ...;
* Change pexp_r for the next year using the  previous prices   
    pexp_r(i) = pexp_prev(i) + 0.33*(PRICE.L(i) - pexp_prev(i));
    );

Hope this helps
Cheers!
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
ZNSen
User
User
Posts: 9
Joined: 6 years ago

Re: How to build a recursive dynamic model

Post by ZNSen »

Many thanks. I successfully solved the problem
Post Reply