non-linear least squares with many regressors

For questions regarding programming in the EViews programming language.

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

Gin
Posts: 22
Joined: Wed Oct 19, 2016 10:26 am

non-linear least squares with many regressors

Postby Gin » Mon Oct 24, 2016 8:06 am

Hi all,

I have a question on defining coefficients for non-linear least squares with many regressors.

I have 14 variables with similar name pattern. They all start with "n_", e.g. n_cpi, n_gdp, n_ism, etc. I need to do non-linear LS of the form

dep = constant + beta1*n_cpi*(1 + gamma11*date_dummy1 + gamma12*date_dummy2)
+ beta2*n_gdp*(1 + gamma21*date_dummy1 + gamma22*date_dummy2)
+ ...
+ beta14*n_ism*(1 + gamma141*date_dummy1 + gamma142*date_dummy2)

where beta1 is the coefficients for the overall response to gdp, gamma11 and gamma12 are the coefficients for the two subperiods, etc. I can't figure out how to properly specify the gamma coefficient using a loop. Can anyone give me a suggestion?

Thanks!

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

Re: non-linear least squares with many regressors

Postby EViews Gareth » Mon Oct 24, 2016 8:23 am

Code: Select all

%varlist = "n_cpi n_gdp n_ism" %spec = "dep = constant" for !i=1 to @wcount(%varlist) %var = @word(%varlist, !i) series {%var} = nrnd %spec = %spec + " + beta" + @val(!i)+"*" + %var + "(1+gamma" + @val(!i) + "1*date_dummy1 + gamma" + @val(!i)+"2*data_dummy2)" next
or something similar.

Gin
Posts: 22
Joined: Wed Oct 19, 2016 10:26 am

Re: non-linear least squares with many regressors

Postby Gin » Mon Oct 24, 2016 2:31 pm

Hi Gareth,

thank you for the post. I have run your code. But the program stops at the fourth line of the loop.

Code: Select all

%spec = %spec + " + beta" + @val(!i)+"*" + %var + "(1+gamma" + @val(!i) + "1*date_dummy1 + gamma" + @val(!i)+"2*data_dummy2)"
and tells me that "%SPEC is not defined or is an illegal command". So the first %spec returns a temporary string variable, right? But the string command would result in a syntax error... Can you give me a hint here of how to return the equation specification as a string?

I noticed I made a mistake in the first post. Sorry for that.. The equation for NLS should look like
dep = constant + beta1*n_cpi*(1 + gamma1*date_dummy1 + gamma2*date_dummy2)
+ beta2*n_gdp*(1 + gamma1*date_dummy1 + gamma2*date_dummy2)
+ ...
+ beta14*n_ism*(1 + gamma1*date_dummy1 + gamma2*date_dummy2)

where gamma coefficient stays constant for each variable.

I have modified your code as below

Code: Select all

coef(1) const ' declare constant coef(14) beta ' declare coefficient for each variable (n_gdp, n_cpi, n_ism, etc). there are 14 variables in total coef(2) gamma ' declare coefficient for time dummies %varlist = "n_cpi n_gdp n_ism" %spec = "dep = constant" for !i=1 to @wcount(%varlist) '''' returns number of strings in %varlist %var = @word(%varlist, !i) ''' picking out !i-th word in %varlist series {%var} = nrnd string spec = %spec + "+ beta" + "(" + @val(!i) + ")" + "*" + %var + "*" + "(1+ gamma(1)*date_dummy1 + gamma(2)*date_dummy2)" next
But the code break down at the fourth line in the loop...

Would be nice if you could take a look at this.

Thanks a lot!

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

Re: non-linear least squares with many regressors

Postby EViews Gareth » Mon Oct 24, 2016 3:06 pm

Sorry, I should have used @str rather than @val


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests