Monte Carlo Simulation

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt

Imhlanga
Posts: 6
Joined: Wed Jun 30, 2010 12:42 am

Monte Carlo Simulation

Postby Imhlanga » Mon Jul 04, 2011 4:02 am

I am trying to write a monte carlo program that i can use to analyse the coefficients of three different economic agents; debty hater, debty lover and debty stabiliser. For all of them, the begining value of Debt to gdp ratio (Debt) is 53.65.
The primary balance is P, which is a fraction q =(r-g)/(1+g) of the the debt-to-gdp ratio in the last period. Thus Pb=q*Debt(-1), this applies for all agents.
Now, what makes these agents different is the following:

debt stabiliser: series Ps(t)=Pb+e(t), series Debts=Debt(-1)-(Ps(t)-Pb(t))
debt hater: series Ph(t)=Pb-1+e(t) , series Debth=Debt(-10-(Ph(t)-Pb(t))
debt lover: Pl=Pb(t)+1+e(t), series Debtl=Debt(-10-(Pl(t)-Pb(t))
in all cases, e(t) is a random error with zero mean and 1.5 standard deviation, truncated to be between in the interval (-3,3)
After generating corresponding series of P and Debt, i want to run the regreesion of the following type: Pi=c(1)+c(2)*Debt, for each agent i will repeat bthis to produce 100 coeficients, which i will then plot as a kernel density distribution in one set of axes.

'sample will have 20 observations (20 years), so that 100 betas will be simulated
'create data series for debty
'begining value of 53.65 and normally distributed random error terms with mean of zero and standard deviation of 1.5
scalar r=0.0352
scalar g=0.0301
scalar q=(r-g)/(1+g)
'assign number of replications to a control variable
!reps = 100
for !i = 1 to !reps
genr Debt{!i}=53.65
smpl 1 20
genr et{!i}=error 'the error has already been generated using an add in.
'simulate P1 data (only for 20 obs)
genr P1{!i}= q*Debt{!i}(-1)
smpl 1 20
genr PS{!i}=P1{!i}+et{!i}
smpl 1 20
genr Debtys{!i}=Debt{!i}-(PS{!i}-P1{!i})
smpl 1 20
matrix(!reps,2) results
equation eq1{!i}.ls PS{!i}=c(1)+c(2)*Debtys{!i}(-1)
results(!i,1)=eq1{!i}.@coefs(1)
'and store each coefficient estimate in a series
series c1 = eq1{!i}.@coefs(1)
series c2 = eq1{!i}.@coefs(2)
group g1 c1 c2
g1.distplot kernel
smpl 1 20
next


where am i getting this wrong?

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: Monte Carlo Simulation

Postby EViews Gareth » Mon Jul 04, 2011 9:27 am

Code: Select all

genr Debt{!i}=53.65
Doesn't mean assign into the !ith value of the series Debt. Rather it means assign into the entire Debt series, with a lead of !i. I'm not sure I follow what you're doing, so I'm not sure if that is what you had in mind.


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests