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!
non-linear least squares with many regressors
Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt
-
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
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
Re: non-linear least squares with many regressors
Hi Gareth,
thank you for the post. I have run your code. But the program stops at the fourth line of the loop.
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
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!
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)"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
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
Sorry, I should have used @str rather than @val
Who is online
Users browsing this forum: No registered users and 2 guests
