Loop for st deviation and replacing a variable

For questions regarding programming in the EViews programming language.

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

Rosa.hh
Posts: 22
Joined: Tue Dec 14, 2010 8:07 am

Loop for st deviation and replacing a variable

Postby Rosa.hh » Wed Dec 15, 2010 8:00 am

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!

Rosa.hh
Posts: 22
Joined: Tue Dec 14, 2010 8:07 am

Re: Loop for st deviation and replacing a variable

Postby Rosa.hh » Wed Dec 15, 2010 8:29 am

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}})

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

Postby startz » Wed Dec 15, 2010 8:32 am

How do I programme: c=a, replace c=b if a is different than NA?

Code: Select all

c = @recode(a<>NA,a,b)

Rosa.hh
Posts: 22
Joined: Tue Dec 14, 2010 8:07 am

Re: Loop for st deviation and replacing a variable

Postby Rosa.hh » Wed Dec 15, 2010 9:18 am

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

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

Postby startz » Wed Dec 15, 2010 9:32 am

Is it possible you have the sample miss-set, so that some observations are unaffected by the @recode?

Rosa.hh
Posts: 22
Joined: Tue Dec 14, 2010 8:07 am

Re: Loop for st deviation and replacing a variable

Postby Rosa.hh » Wed Dec 15, 2010 9:54 am

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

Postby startz » Wed Dec 15, 2010 10:03 am

@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.

Rosa.hh
Posts: 22
Joined: Tue Dec 14, 2010 8:07 am

Re: Loop for st deviation and replacing a variable

Postby Rosa.hh » Wed Dec 15, 2010 10:20 am

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
Attachments
grwth_rate.prg
program
(351 Bytes) Downloaded 636 times
growth rate.wf1
database
(9.91 KiB) Downloaded 640 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

Postby startz » Wed Dec 15, 2010 10:43 am

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
First off, your program won't run because the for statement doesn't have a matching end.
Second, in the workfile a_rer_gq is never NA.

Rosa.hh
Posts: 22
Joined: Tue Dec 14, 2010 8:07 am

Re: Loop for st deviation and replacing a variable

Postby Rosa.hh » Wed Dec 15, 2010 11:20 am

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,

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

Postby startz » Wed Dec 15, 2010 11:34 am

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)


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests