Page 3 of 3

Re: Create continuous future contracts

Posted: Sat Feb 08, 2014 1:20 pm
by d952
Thank you very much for your great helps. Finally I could find where is the problem. in the recoding that you sent me before, it was something like this:

series pc_merged1=@recode(pc_clf1984(7)<>na, pc_clh1984, pc_clj1984)

so it had to replace 7 observation before NA at the end of the series, but the issue was that my data set had many NAs between and even before starting date of the data, so the codes where doing replacement where ever in the data they found a NA, and it was generating a big mess :)
Now I removed the NAs and the problem is solved.

The codes that is generating the series that I want is this:

series pc_merged1=@recode(pc_clf1984(7)<>na, pc_clh1984, pc_clj1984)
series pc_merged2=@recode(pc_clg1984(7)<>na, pc_merged1, pc_clk1984)
series pc_merged3=@recode(pc_clh1984(7)<>na, pc_merged2, pc_clm1984)
series pc_merged4=@recode(pc_clj1984(7)<>na, pc_merged3, pc_cln1984)
series pc_merged5=@recode(pc_clk1984(7)<>na, pc_merged4, pc_clq1984)
series pc_merged6=@recode(pc_clm1984(7)<>na, pc_merged5, pc_clu1984)
series pc_merged7=@recode(pc_cln1984(7)<>na, pc_merged6, pc_clv1984)
series pc_merged8=@recode(pc_clq1984(7)<>na, pc_merged7, pc_clx1984)
series pc_merged9=@recode(pc_clu1984(7)<>na, pc_merged8, pc_clz1984)

series pc_merged10=@recode(pc_clv1984(7)<>na, pc_merged9, pc_clf1985)
series pc_merged11=@recode(pc_clx1984(7)<>na, pc_merged10, pc_clg1985)
series pc_merged12=@recode(pc_clz1984(7)<>na, pc_merged11, pc_clh1985)
series pc_merged13=@recode(pc_clf1985(7)<>na, pc_merged12, pc_clj1985)
series pc_merged14=@recode(pc_clg1985(7)<>na, pc_merged13, pc_clk1985)
series pc_merged15=@recode(pc_clh1985(7)<>na, pc_merged14, pc_clm1985)
series pc_merged16=@recode(pc_clj1985(7)<>na, pc_merged15, pc_cln1985)
series pc_merged17=@recode(pc_clk1985(7)<>na, pc_merged16, pc_clq1985)
series pc_merged18=@recode(pc_clm1985(7)<>na, pc_merged17, pc_clu1985)
series pc_merged19=@recode(pc_cln1985(7)<>na, pc_merged18, pc_clv1985)
series pc_merged20=@recode(pc_clq1985(7)<>na, pc_merged19, pc_clx1985)
series pc_merged21=@recode(pc_clu1985(7)<>na, pc_merged20, pc_clz1985)

and the final series that is my destination is pc_merged21, the above codes are only for the years 1984-1985 and should be extended to 2013, so you can imagine how much time it takes to extend it, thats why Im trying to make loops to do that, if I can :D
Thanks again

Re: Create continuous future contracts

Posted: Mon Feb 10, 2014 12:58 pm
by EViews Glenn
Same principle, we just need to do the lags across years as well

Code: Select all

' seed the lags
%name1 = "PC_CLF1984"
%name2 = "PC_CLG1984"
%name3 = "PC_CLH1984"

svector(1000) merge_cmnds

' initialize
series pc_merged = PC_CLH1984

' loop over years and labels
!k = 1
for !j = 1984 to 2013
   for %i f g h j k m n q u v x z
      ' get next name
      %name4 = "PC_CL" + @upper(%i) + @str(!j)
      ' assign to series %4 when series %1(7)=na
      if (%name4<>%name1 and %name4<>%name2 and %name3<>%name1) then
         pc_merged = @recode({%name1}(7)<>na, pc_merged, {%name4})
         merge_cmnds(!k) = "pc_merged = @recode(" + %name1 + "(7)<>na, pc_merged, " + %name4 + ")"
         !k = !k + 1
      endif
      ' recurse lags over names
      %name1 = %name2
      %name2 = %name3
      %name3 = %name4
   next
next

The svector merge_cmnds and the !k counter are used to show you the commands that are formed by the loop. You can comment them out once you are satisfied that it is doing what you want.

Re: Create continuous future contracts

Posted: Tue Feb 11, 2014 9:12 am
by d952
Thank you very much for you help.

Re: Create continuous future contracts

Posted: Wed Feb 12, 2014 7:53 am
by d952
[quote="EViews Glenn"]Thanks. I think you're still going to have to be more precise about what you want done.

Re: Create continuous future contracts

Posted: Wed Feb 12, 2014 1:07 pm
by EViews Glenn
I'm not entirely certain what you meant by the last comment, but I do believe there's a general principle here. The more precise people can be about what they want, the easier it us for me (and more typically, Gareth) to follow and offer suggestions.

Re: Create continuous future contracts

Posted: Thu Feb 13, 2014 4:21 am
by d952
My last comment was that I thanked you, it works perfectly and Im trying to modify it to the whole sample. I dont know how the above comment appeared here (about being more precise) it was one of your comments that you told me before but I really dont know how it appears here again :D
thanks again

EViews Glenn wrote:I'm not entirely certain what you meant by the last comment, but I do believe there's a general principle here. The more precise people can be about what they want, the easier it us for me (and more typically, Gareth) to follow and offer suggestions.