GENERATING RANDOM NORMAL DRAWS

For questions regarding programming in the EViews programming language.

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

ndzama
Posts: 15
Joined: Tue Aug 10, 2021 8:33 am

GENERATING RANDOM NORMAL DRAWS

Postby ndzama » Sun Dec 10, 2023 6:57 am

Dear Eviews team

'==========================='
'CALCUTLATING FORECAST ERROR, ITS VARIANCE, and generating RANDOM DRAWS
'==============================
genr error_CA_{%h}Y_{%c}_AR = CA_{%c} - CA_{%c}_0_AR 'actual-forecast = error
scalar errorvariance_CA_{%h}Y_{%c}_AR=@var( error_CA_{%h}Y_{%c}_AR) 'Forecast error variance
scalar num_draws_AR = 1000 'Set the number of random draws you want to generate random draws from the normal distribution
series draws_errorvariance_CA_{%h}Y_{%c}_AR=@rnorm(num_draws, 0, @sqrt(errorvariance_CA_{%h}Y_{%c}_AR)) ' generate random draws from
the normal distribution //

ON THE LAST LINE OF THIS CODE I KEEP GETTING A SYNTAX ERROR. I cannot figure out why. Please advice.

Kind Regards,
Florence

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

Re: GENERATING RANDOM NORMAL DRAWS

Postby EViews Gareth » Sun Dec 10, 2023 7:05 pm

Without the rest of the code and/or workfile impossible to say. But you probably need to have had defined num_draws
Follow us on Twitter @IHSEViews

EViews Matt
EViews Developer
Posts: 557
Joined: Thu Apr 25, 2013 7:48 pm

Re: GENERATING RANDOM NORMAL DRAWS

Postby EViews Matt » Mon Dec 11, 2023 11:23 am

Quick follow up... EViews' @rnorm function is parameterless since it returns draws from the standard normal distribution. You can adjust your genr statement accordingly, e.g.,

Code: Select all

series draws_errorvariance_CA_{%h}Y_{%c}_AR = @rnorm * @sqrt(errorvariance_CA_{%h}Y_{%c}_AR)

ndzama
Posts: 15
Joined: Tue Aug 10, 2021 8:33 am

Re: GENERATING RANDOM NORMAL DRAWS

Postby ndzama » Wed Dec 20, 2023 8:25 am

EViews Matt wrote:Quick follow up... EViews' @rnorm function is parameterless since it returns draws from the standard normal distribution. You can adjust your genr statement accordingly, e.g.,

Code: Select all

series draws_errorvariance_CA_{%h}Y_{%c}_AR = @rnorm * @sqrt(errorvariance_CA_{%h}Y_{%c}_AR)



Thank you for the responses.
The problem with @rnorm syntax does not allow multiple random draws, e.g 1000

@rmvnorm works well for a VAR model. I can generate 1000 random draws.
matrix draw_var_{%c}=@rmvnorm(covs_{%c}, 1000) 'random draws from the normal distribution

How can I draw these 1000 draws using a simple AR model? I have tried @rnorm and @nrnd

ndzama
Posts: 15
Joined: Tue Aug 10, 2021 8:33 am

Re: GENERATING RANDOM NORMAL DRAWS

Postby ndzama » Fri Dec 22, 2023 8:54 am

Greetings,

Problem solved. After the @rnorm code you suggested, I simply created a new page with 1000 random observations, then wala!


Again thank you for your help. Much appreciated.


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 3 guests