楼主: 芦荟航
2329 0

[问答] 求大神指点!!!!GAMS软件的代码问题 [推广有奖]

  • 0关注
  • 2粉丝

已卖:221份资源

硕士生

34%

还不是VIP/贵宾

-

威望
0
论坛币
54 个
通用积分
4.8041
学术水平
1 点
热心指数
0 点
信用等级
0 点
经验
346 点
帖子
17
精华
0
在线时间
294 小时
注册时间
2012-6-30
最后登录
2022-6-3

楼主
芦荟航 在职认证  发表于 2015-7-10 14:17:29 |AI写论文
2论坛币
Untitled_2.gms

*no technology progress
*11generations :first 8 works
*save for "Untitled_3.gms"
Options limcol=0,limrow=0,solprint=off,decimals=4;
Set m generations /m1*m11/;
Set mi(m) first generation /m1/;
Set mj(m) generations working /m1*m8/;
Set mm(m) retired generations /m9*m11/;
Set mn(m) last generations /m11/;
Scalars
ces1 intertemporal elasticity of substitution
ir interest rate
w2
tw wage tax rate
tr interest tax rate
tc consumption tax rate
pr1 pension rate
n birth rate
dr1
;
ces1=1.25;
ir=0.19;
tw=0.11;
tr=0.21;
tc=0.2;
pr1=0.5;
n=1.2;
Parameter h1(m) effective labour supply;
  h1(m)=1; h1(mm)=0;
Parameter po1(m) population of age group m ;
po1(mi)=1;loop(m,po1(m+1)=po1(m)/n);
dr1=sum(mm,po1(mm))/sum(m,po1(m)*h1(m));
Parameter p production function prameter;
p=0.4;
Parameter lc,k1,y1,yy1 output;
yy1=1;
Parameter kc2;
Positive variables
w1 wage rate per unit of human capital
a1 unit of measure for the production function
kc1 capital stock
c1(m) consumption level for goods by generation m
lc1 human captial stock
g1 government expenditure
ta1(m) government tax income
pen1(m) pension
cr1 contribution rate
Free variables
tp1
s1(m) saving variable
as1(m)
di1(m)
ob objective function
wal walras variable
Equations
ep1
ep2
ep3

ec1(m)
ec2(m)
ec3(m)
ec4(m)
ec5(m)
ec6(m)
ec8(m)
eg1(m)
eg2
eg3

ee1
ee2
ee3
eob
;
*Equtions
ep1..w1=e=(1-p)*a1*((kc1/lc1)**p);
ep2..ir=e=p*a1*(kc1/lc1)**(p-1);
ep3..yy1=e=a1*(kc1**P)*(lc1**(1-p));

*consumer problem :calibration of cons. and ces1.
ec1(m+1)..c1(m+1)=e=(((1+ir*(1-tr))/(1+tp1))**ces1)*c1(m);
ec2(m)..di1(m)=e=w2*(1-cr1)*(1-tw)*h1(m)+ir*(1-tr)*as1(m)+(1-tw)*pen1(m);
ec3(m)..s1(m)=e=di1(m)-c1(m)*(1+tc);
ec4(mn)..s1(mn)=e=-as1(mn);
ec5(m+1)..as1(m+1)=e=as1(m)+s1(m);
ec6(mm)..pen1(mm)=e=pr1*w2;

*government sector
eg1(m).. ta1(m)=e=tw*(1-cr1)*w2*h1(m)+tr*ir*as1(m)+tc*c1(m)+tw*pen1(m);
eg2.. g1=e=sum(m,po1(m)*ta1(m));
eg3.. sum(mm,po1(mm)*pen1(mm))=e=cr1*sum(m,po1(m)*h1(m)*w2);

*aggregation and equilibrium conditions
ee1.. lc1=e=sum(m,po1(m)*h1(m));
ee2.. kc2=e=sum(m,po1(m)*as1(m));
ee3.. wal=e=yy1-sum(m,po1(m)*(c1(m)+s1(m)+ta1(m)));
eob.. ob=e=10;

*restrictions
as1.fx(mi)=0;
lc1.l=1 ;
pen1.fx(mj)=0;
*initial guesses
w1.l=1;a1.l=2;
kc1.l=0.6;
c1.l(m)=1;
s1.l(m)=1;
as1.l(mm)=1;
di1.l(m)=1;
tp1.l=0.2;
wal.l=0;
g1.l=1;
ta1.l(m)=0;
pen1.l(m)=0.4;
cr1.l=0.25;

Model ca1/ep1,ep2,ep3,ee1,eob/
Model ca2/ec1,ec2,ec3,ec4,ec5,ec6,eg1,eg2,eg3,ee2,ee3,eob/;
Option nlp=minos;
ca1.HOLDFIXED=1;
Solve ca1 using nlp minimizing ob;
w2=w1.l;
kc2=kc1.l;
ca2.HOLDFIXED=1;
Solve ca2 using nlp minimizing ob;
lc=sum(mj,po1(mj)*h1(mj));
k1=lc*(kc1.l/lc1.l);
y1=a1.l*(k1**p)*(lc**(1-p));

Parameter th total human captial stock;
th=sum(m,po1(m)*h1(m));

  Display  w1.l,w2,kc1.l,kc2,a1.l,di1.l,c1.l,s1.l,as1.l,
         ces1,lc1.l,lc,wal.l,tp1.l,pen1.l,cr1.l,th;



Untited_3.gms


$include"Untitled_2.gms"
*save for "Untitled_4.gms"
Set t welfare periods/t1*t60/
Set ti(t) first period;ti(t)=yes$(ord(t) eq(1));
set tn(t) last two period/t59,t60/
Scalars ces intertemporal substitution elast;
        ces=ces1;
Parameter dr(t) dependency ratio;
Parameter tp(t) pure rate of time preference;
   tp(t)=tp1.l;
Parameter nn(t) population growth rate;
    nn(t)=n;
Parameter a(t) output coefficient;
    a(t)=a1.l;
Parameter h(t,m) effective labour supply per cohort;
    h(t,m)=h1(m);
Parameter gov(t) government expenditure;
    gov(ti)=g1.l;
loop(t,gov(t+1)=nn(t)*gov(t));
Parameter pr(t) pension rate;
    pr(t)=pr1;
Parameter pom(t,m),pop(t) population at time t for age-group m;
pom(ti,m)=po1(m);
loop(t,pom(t+1,mi)=pom(t,mi)*nn(t));
loop(t,pom(t+1,m+1)=pom(t,m));
Parameter l(t) aggregate effective labour supply;
l(ti)=lc;
loop(t,l(t)=sum(m,pom(t,m)*h(t,m)));
dr(t)=sum(mm,pom(t,mm))/sum(m,pom(t,m)*h(t,m))*100;
Positive Variables
w(t) wages per unit of human capital
tw1(t) wage tax
r(t) rental rate of physical capital
k(t) physical capital stock
y(t) output
c(t,m) consumption level for goods by generation m
cr(t) contribution rate
tax(t,m) government tax income
pen(t,m) pension;
y.lo(t)=0.1 ;
y.up(t)=30000;
k.lo(t)=0.1;
k.up(t)=30000;
c.up(t,m)=1;
pen.up(t,m)=1;
w.lo(t)=0.1;
w.up(t)=0.5;
r.lo(t)=0.02;
r.up(t)=0.5;
cr.lo(t)=0.07;
cr.up(t)=0.5;
tw1.up(t)=0.2;
tax.up(t,m)=1;
Free variables
as(t,m)
sv(t,m)
di(t,m)
walras(t)
oc;
sv.up(t,m)=1;
sv.lo(t,m)=-0.3;
as.up(t,m)=1;
as.lo(t,m)=-0.01;
di.up(t,m)=1;
di.lo(t,m)=0;

Equations
es1(t)
es2(t)
es3(t)
es4(t)

eh1(t,m)
eh2(t,m)
eh3(t,m)
eh4(t,m)
eh5(t,m)
eh6(t,m)
eh7(t,m)
eh8(t,m)
eh9(t,m)
eh10(t,m)
eh11(t,m)

ea1(t,m)
ea2(t)
ea3(t)
eq1(t)
eq2(t)
eq3(t)
eoc
;
*Equations
es1(t)..w(t)=e=((1-p)*a(t)*((k(t)/l(t))**p));
es2(t)..r(t)=e=p*a(t)*(k(t)/l(t))**(p-1);
es3(t)..y(t)/l(t)=e=a(t)*((k(t)/l(t))**p);
es4(t)..tw1(t+1)=e=tw1(t)*(w(t+1)/w(t));

eh1(t+1,m+1)..c(t+1,m+1)=e=(((1+r(t)*(1-tr))/(1+tp(t)))**ces)*c(t,m);
eh2(tn+1,m)..c(tn+1,m)=e=c(tn,m);
eh3(t,m)..di(t,m)=e=w(t)*(1-cr(t))*(1-tw1(t))*h(t,m)+r(t)*(1-tr)*as(t,m)
                    +(1-tw1(t))*pen(t,m)-c(t,m)*tc;
eh4(t,m)..sv(t,m)=e=di(t,m)-c(t,m);
eh5(t,"m11")..sv(t,'m11')=e=-as(t,'m11');
eh6(t+1,m+1)..as(t+1,m+1)=e=as(t,m)+sv(t,m);
eh7(ti,mm)..pen(ti,mm)=e=pr(ti)*w(ti)*sum(mj,h(ti,mj))/card(mj);
eh8(t+1,'m9')..pen(t+1,'m9')=e=pr(t)*w(t)*(1-h(t,'m9'));
eh9(t+1,'m10')$(h(t,'m9')gt(0))..pen(t+1,'m10')=e=pr(t)*w(t);
eh10(t+1,mm+1)$(h(t,'m9')eq(0))..pen(t+1,mm+1)=e=pen(t,mm);
eh11(t+1,mm+2)$(h(t,'m10')gt(0))..pen(t+1,mm+2)=e=pen(t,mm+1);

ea1(t,m)..tax(t,m)=e=tw1(t)*(1-cr(t))*w(t)*h(t,m)+tr*r(t)*as(t,m)
                   +tc*c(t,m)+tw1(t)*pen(t,m);
ea2(t)..sum(m,pom(t,m)*pen(t,m))=e=cr(t)*sum(m,pom(t,m)*h(t,m)*w(t));
eq1(t)..k(t)=e=sum(m,pom(t,m)*as(t,m));
eq2(t)..walras(t)=e=y(t)-sum(m,pom(t,m)*(c(t,m)+sv(t,m)+tax(t,m)));

eoc..oc=e=10;
*restrictions
k.fx(ti)=k1;
loop(t,k.l(t+1)=nn(t)*k.l(t));
as.fx(t,mi)=0;
as.fx(ti,m)=as1.l(m);
tw1.fx(ti)=tw;
*Initial guesses
tax.l(t,m)=ta1.l(m);
cr.l(t)=cr1.l;
w.l(t)=w1.l;
r.l(t)=ir;
y.l(ti)=y1;
loop(t,y.l(t+1)=nn(t)*y.l(t));
c.l(t,m)=c1.l(m);
sv.l(t,m)=s1.l(m);
as.l(t,m)=as1.l(m);
di.l(t,m)=di1.l(m);
pen.l(t,m)=pen1.l(m);
pen.fx(t,mj)=0;
walras.l(t)=0;
tw1.l(t+1)=tw;

Model sim1/es1,es2,es3,es4,eh1,eh2,eh3,eh4,eh5,eh6,eh7,eh8,eh9,eh10,eh11,
          ea1,ea2,eq1,eq2,eoc/;
Option nlp=minos5;
sim1.HOLDFIXED=1;
Solve sim1 using nlp minimizing oc;

loop(t,nn(t+3)=nn(t+2)-0.01);
loop(t,nn(t+5)=nn(t+4)-0.038);
loop(t,nn(t+7)=nn(t+6)-0.058);
loop(t,nn(t+9)=nn(t+8));
loop(t,pom(t+1,mi)=pom(t,mi)*nn(t));
loop(t,pom(t+1,m+1)=pom(t,m));
l(ti)=lc;
loop(t,l(t)=sum(m,pom(t,m)*h(t,m)));
dr(t)=sum(m,pom(t,m)*(1-h(t,m)))/sum(m,pom(t,m)*h(t,m))*100;

option nlp=conopt2;
Solve sim1 using nlp minimizing oc;


option nlp=MINOS5, solprint=on;
Solve sim1 using nlp minimizing oc;


Untited_4.gms
$include "Untitled_3.gms"
*save for "Untitled_5.gms"
loop(t,nn(t+5)=nn(t+4)-0.038-0.007);
loop(t,nn(t+7)=nn(t+6)-0.058);
loop(t,nn(t+9)=nn(t+8));
loop(t,nn(t+10)=nn(t+9)+0.0018);
loop(t,nn(t+30)=1);
loop(t,pom(t+1,mi)=pom(t,mi)*nn(t));
loop(t,pom(t+1,m+1)=pom(t,m));
   l(ti)=lc;
loop(t,l(t)=sum(m,pom(t,m)*h(t,m)));
dr(t)=sum(mm,pom(t,mm))/sum(m,pom(t,m)*h(t,m))*100;
   solve sim1 using nlp minimizing oc;
  Display  w1.l,w2,kc1.l,kc2,a1.l,di1.l,c1.l,s1.l,as1.l,
         ces1,lc1.l,lc,wal.l,tp1.l,pen1.l,cr1.l,th;
Untitled_5.gms


$include "Untitled_4.gms"
*increase retirement age
set it/1*5/
loop(it,h(t+10,"m9")=ord(it)/5;
l(t)=sum(m,pom(t,m)*h(t,m));
dr(t)=sum(m,pom(t,m)*(1-h(t,m)))/sum(m,pom(t,m)*h(t,m))*100;
option nlp=minos;
Solve sim1 using nlp minimizing oc;);
  Display  w1.l,w2,kc1.l,kc2,a1.l,di1.l,c1.l,s1.l,as1.l,
         ces1,lc1.l,lc,wal.l,tp1.l,pen1.l,cr1.l,th;

这个代码是用Untitled_3调用2;再用4调用3;再用5调用4..但是每次输出的都是程序Untitled_2的数据结果,不知道哪里出了问题。。。。
求各位大神指点。。。。在线等




关键词:GAMS软件 gams GAM AMS substitution generation technology interest 软件

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-30 11:30