Hi Yi-Nung Yang and Sven,
Thanks for your reply.
@Yi-Nung Yang
Your suggestion works fine. Thank you for it.
@Sven
I will try out your suggestion. It seems to be the more elegant way. ;-)
Cheers,
Artur
P.S.: For those who are interested in the function:
Creates:
1. Separated series of positive and negative changes of the variable(s)
of interest.
2. 'Regime series' or separated partial sum processes [cumulation of all
positive (negative) changes] of the variable(s) of interest.
------------------------------------------------
function list Regime_Series (list Y "List of variables")
smpl --full
list olist = null #Output list
loop foreach i Y --quiet
series pd_d_$i = 0 #Generate series for positive changes
series nd_d_$i = 0 #Generate series for negative changes
endloop
list dY = diff(Y) #1st difference of Y
#Attribute the first differences to the series
loop foreach i dY --quiet
smpl $i > 0 --restrict #Restrict only positive changes
pd_$i = $i #Generate series of positive changes
smpl --full
smpl $i < 0 --restrict #Restrict only negative changes
nd_$i = $i #Generate series of negative changes
smpl --full
setinfo pd_$i -d "Positive values of $i"
setinfo nd_$i -d "Negative values of $i"
#------------- add pd_$i nd_$i to olist
olist += pd_$i nd_$i
endloop
#Create partial sum process
loop foreach i Y --quiet
series $i_p = 0
series $i_n = 0
series $i_p = $i_p(-1) + pd_d_$i #Partial sum process of positive
changes
setinfo $i_p -d "Positive partial sum of $i"
series $i_n = $i_n(-1) + nd_d_$i #Partial sum process of negative
changes
setinfo $i_n -d "Negative partial sum of $i"
# ---------- add $i_p $i_m to olist
olist += $i_p $i_n
endloop
# ------- return
return olist
end function
------------------------------------------------
Am 12.05.2010 10:00, schrieb Sven Schreiber:
Artur T. schrieb:
> # create partial sum process
> loop foreach i Y --quiet
> series $i_p = 0
> series $i_m = 0
> series $i_p = $i_p(-1) + pd_d_$i #Partial sum process of positive
> changes
> series $i_m = $i_m(-1) + nd_d_$i #Partial sum process of negative
>
unrelated to your question: the cum() function may be helpful here
> I would like to add the series $i_p and $i_m to the current variables
> but I cannot find out how to use the "return" command correctly in this
> context. Does anybody have a suggestion?
>
If the number of returned series is known in advance and small, you
might also try the pointer variant:
function void getoutput(series *out1, series *out2)
...
end function
series output1=0
series output2=0
getoutput(&output1,&output2)
The advantage is that the names of the returned series are controlled
not by the function code, but by the calling code.
HTH,
sven
_______________________________________________
Gretl-users mailing list
Gretl-users(a)lists.wfu.edu
http://lists.wfu.edu/mailman/listinfo/gretl-users