Hi!
I started using Eviews 7 quite recently and I have two questions:
1. How do I write a loop to generate @cumstdev for a set of variables?
I want to create a loop to generate the cumulative standard deviation of a variable (total of 29). With the forum's help I have manage to calculate the stdev of one variable, but when I try to loop as below I get an error message "indep1 is not defined in series". Anyone knows how to fix this?
smpl @all
for !j = 1 to 29 'the independent variables
%indep1 = "a_rer_gq"
%indep2 ="b_exp_gq"
%indep3 = "c_imp_gq"
[...until %indep29]
series temp = @cumstdev(indep{!j})
2. My second question is the following: How do I programme: c=a, replace c=b if a is different than NA?
I want to create a variable (grwth_r) which is equal to the values of 2 other variables. The general idea is:
series grwth_r=a_rer_gq if max_total=na (this is equal to the first half of the observations)
and
grwth_r=max_total if max_total is different than na (equivalent to the second half of observations)
As I am dealing with NAs I have tried the recode command however it is not working
@recode(max_total=na, a_rer_gq, max_total)
I have also tried the following but its not workin either):
smpl @first @last-(!endobs-!halfobs)
series grwth_r=a_rer_gq
smpl @last-(!halfobs-1) @last
series grwth_r= max_total
Thank you very much for your advice!
Loop for st deviation and replacing a variable
Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt
Re: Loop for st deviation and replacing a variable
I found the answer to my first question (please see below). However, although I'm sure it's very very simple, I still do not know how to replace a variable with the value of another one (2nd question detailed above), meaning: How do I programme: c=a, replace c=b if a is different than NA?
Thanks!
To create a loop for the cum st deviation, % and double brackets are needed:
series temp_indep{!j} = @cumstdev ({%indep{!j}})
Thanks!
To create a loop for the cum st deviation, % and double brackets are needed:
series temp_indep{!j} = @cumstdev ({%indep{!j}})
-
startz
- Non-normality and collinearity are NOT problems!
- Posts: 3796
- Joined: Wed Sep 17, 2008 2:25 pm
Re: Loop for st deviation and replacing a variable
How do I programme: c=a, replace c=b if a is different than NA?
Code: Select all
c = @recode(a<>NA,a,b)Re: Loop for st deviation and replacing a variable
Startz, thanks for replying. I actuallyl tried that and it is not working, for some reason the variable only takes the values of max_total and not of a_rer_gq when max_total=NA
Do you know another approach?
My code is: series grwth_r=@recode(a_rer_gq<>NA, a_rer_gq, max_total)
I was thinking of approaching the problem it in another way saying:
grwth_r=a_rer_gq for the first half of the sample
grwth_r= max_total for the second half of the sample
I have done this but did not succeed, after running the last part my variable only takes the values of max_total (and not of a_rer_gq when max_total=NA). As I will run this for 29 variables for 13 countries, I cannot keep the cut off point of my sample fixed). This is what I tried (didnt work):
' smpl @first @last-(!endobs-!halfobs)
' series grwth_r=a_rer_gq
'smpl @last-(!halfobs-1) @last
'series grwth_r= max_total
Do you know another approach?
My code is: series grwth_r=@recode(a_rer_gq<>NA, a_rer_gq, max_total)
I was thinking of approaching the problem it in another way saying:
grwth_r=a_rer_gq for the first half of the sample
grwth_r= max_total for the second half of the sample
I have done this but did not succeed, after running the last part my variable only takes the values of max_total (and not of a_rer_gq when max_total=NA). As I will run this for 29 variables for 13 countries, I cannot keep the cut off point of my sample fixed). This is what I tried (didnt work):
' smpl @first @last-(!endobs-!halfobs)
' series grwth_r=a_rer_gq
'smpl @last-(!halfobs-1) @last
'series grwth_r= max_total
-
startz
- Non-normality and collinearity are NOT problems!
- Posts: 3796
- Joined: Wed Sep 17, 2008 2:25 pm
Re: Loop for st deviation and replacing a variable
Is it possible you have the sample miss-set, so that some observations are unaffected by the @recode?
Re: Loop for st deviation and replacing a variable
Sorry, I dont understand your question.
-
startz
- Non-normality and collinearity are NOT problems!
- Posts: 3796
- Joined: Wed Sep 17, 2008 2:25 pm
Re: Loop for st deviation and replacing a variable
@recode only works within the current sample.
You might want to post the most simple version of a program that fails, along with your workfile, for folks to take a look at.
You might want to post the most simple version of a program that fails, along with your workfile, for folks to take a look at.
Re: Loop for st deviation and replacing a variable
I enclose the database and program. What I want to do is:
create grwth_r=max_total AND replace grwth_r=a_rer_gq when max_total is different than NA
So, for the first half of the period grwth_r should be equal to a_rer_gq AND for the second half of the period it should be equal to max_total.
Thanks for your help!!
'so far I have tried with the following program, but its not working:
!halfobs=39
!endobs=78
for !c = 1 to !halfobs
smpl @all
series grwth_r=0
if max_total=NA then grwth_r=a_rer_gq
endif
series grwth_r=@recode(a_rer_gq<>NA, a_rer_gq, max_total)
smpl @first @last-(!endobs-!halfobs)
series grwth_r=a_rer_gq
smpl @last-(!halfobs-1) @last
series grwth_r= max_total
create grwth_r=max_total AND replace grwth_r=a_rer_gq when max_total is different than NA
So, for the first half of the period grwth_r should be equal to a_rer_gq AND for the second half of the period it should be equal to max_total.
Thanks for your help!!
'so far I have tried with the following program, but its not working:
!halfobs=39
!endobs=78
for !c = 1 to !halfobs
smpl @all
series grwth_r=0
if max_total=NA then grwth_r=a_rer_gq
endif
series grwth_r=@recode(a_rer_gq<>NA, a_rer_gq, max_total)
smpl @first @last-(!endobs-!halfobs)
series grwth_r=a_rer_gq
smpl @last-(!halfobs-1) @last
series grwth_r= max_total
- Attachments
-
- grwth_rate.prg
- program
- (351 Bytes) Downloaded 636 times
-
- growth rate.wf1
- database
- (9.91 KiB) Downloaded 639 times
-
startz
- Non-normality and collinearity are NOT problems!
- Posts: 3796
- Joined: Wed Sep 17, 2008 2:25 pm
Re: Loop for st deviation and replacing a variable
First off, your program won't run because the for statement doesn't have a matching end.I enclose the database and program. What I want to do is:
create grwth_r=max_total AND replace grwth_r=a_rer_gq when max_total is different than NA
So, for the first half of the period grwth_r should be equal to a_rer_gq AND for the second half of the period it should be equal to max_total.
Thanks for your help!!
'so far I have tried with the following program, but its not working:
!halfobs=39
!endobs=78
for !c = 1 to !halfobs
smpl @all
series grwth_r=0
if max_total=NA then grwth_r=a_rer_gq
endif
series grwth_r=@recode(a_rer_gq<>NA, a_rer_gq, max_total)
smpl @first @last-(!endobs-!halfobs)
series grwth_r=a_rer_gq
smpl @last-(!halfobs-1) @last
series grwth_r= max_total
Second, in the workfile a_rer_gq is never NA.
Re: Loop for st deviation and replacing a variable
Thanks for your answer Startz. The matching end was not pasted by mistake, sorry for this.
I am aware the variable a_rer_gq is never NA. It is max_total the one which is equal to NA for the first half of the observations.
So the eviews syntax I am missing is:
series grwth_r
replace grwth_r= max_t_indep1
replace grwth_r=a_rer_gq if max_t_indep1==NA
Thanks,
I am aware the variable a_rer_gq is never NA. It is max_total the one which is equal to NA for the first half of the observations.
So the eviews syntax I am missing is:
series grwth_r
replace grwth_r= max_t_indep1
replace grwth_r=a_rer_gq if max_t_indep1==NA
Thanks,
-
startz
- Non-normality and collinearity are NOT problems!
- Posts: 3796
- Joined: Wed Sep 17, 2008 2:25 pm
Re: Loop for st deviation and replacing a variable
Thanks for your answer Startz. The matching end was not pasted by mistake, sorry for this.
I am aware the variable a_rer_gq is never NA. It is max_total the one which is equal to NA for the first half of the observations.
So the eviews syntax I am missing is:
series grwth_r
replace grwth_r= max_t_indep1
replace grwth_r=a_rer_gq if max_t_indep1==NA
Thanks,
Code: Select all
series grwth_r=@recode(max_t_indep1=NA, a_rer_gq,max_t_indep1)Who is online
Users browsing this forum: No registered users and 2 guests
