Page 1 of 2

@recode

Posted: Mon Apr 14, 2014 10:20 am
by rmoralesaramburu
Hello,

I would like to know what is wrong for the following code

series ddddd=@recode((dfs_h>dfs_h(-1)) and (dfs<dfs_l),1,0)

It doesn't work, does @recode works with "and", "or" ??

I am trying @recode because I can't use the IF inside a FOR loop.

Thanks

Re: @recode

Posted: Mon Apr 14, 2014 10:36 am
by EViews Gareth
Nothing wrong with it that I can see:

Code: Select all

create u 100 series dfs_h = @rnd series dfs=@rnd series dfs_l=@rnd series ddddd=@recode((dfs_h>dfs_h(-1)) and (dfs<dfs_l),1,0)

Re: @recode

Posted: Mon Jun 18, 2018 5:53 am
by shineK
Hi there,

how do i use 2 svector with @recode command?
(related files as attached, please check.)
Actually, the purpose is that if "cusip_alpha" = "scomp_cusp_al", i would like to create a column called DS_s, which is base on "type", in group Scusp, is anyone have better solution for this?
Thank you so much!!!!

Re: @recode

Posted: Mon Jun 18, 2018 8:43 am
by EViews Matt
Hello,

You could use something like,

Code: Select all

series DS_s = @recode(cusip_alpha = scomp_cusp_al, type, na)
and then add DS_s to group Scusp afterword.

Re: @recode

Posted: Tue Jun 19, 2018 12:23 am
by shineK
Hi Matt,

Thank you for your advise. :)
After i tried, it still have some problem, you may see the picture from the attachment
For example,
R4(cusip_alpha) = R3206(Scomp_cusp_al) = 000360206, then
R4(DS_S) should be 544294(type)
But, as you can see from the attchment, R4(DS_s) shows "NA"

i'm not sure is the reason that my data contain string or @recode command can't not be used like this way...
please help, thanks a lot!!!!!!! :D

Code: Select all

%dir="F:\Thesis\Eviews\St11_900A_cusip" %dir1="F:\Thesis\DataFltr_St3\1.Filter\900A_FltrRe\900A_FltrRe_mrg\cusip_alpha\csv" %dir2="F:\Thesis\Eviews\St11_900A_cusip\test_cusp\csv" wfcreate(wf={%country}wf) u 1 5000 import {%dir}\SP500_cusp_s.csv ftype=ascii rectype=crlf skip=0 fieldtype=delimited na="NA" delim=comma colhead=1 eoltype=pad badfield=NA @freq U 1 @smpl @all import {%dir1}\9a_Act1_CuspRun.csv ftype=ascii rectype=crlf skip=0 fieldtype=delimited na="NA" delim=comma colhead=1 eoltype=pad badfield=NA @freq U 1 @smpl @all 'read {%dir}\SP500_cusp_s.csv x1 x2 x3 x4 x5 Scomp_cusp_al $ 'import {%dir2}\900A_Act1_N.csv delim=comma @id cusip_alpha @destid Scomp_cusp_al series DS_s = @recode(scomp_cusp_al = cusip_alpha, type, na) group cuspN scomp_cusp_al s_gvkey syear s_comp_cusip s_comp_tic s_crsp_cusip s_crsp_tic s_crsp_name DS_s

Re: @recode

Posted: Tue Jun 19, 2018 9:49 am
by EViews Matt
Ah, you want to test if each value in scomp_cusp_al matches ANY value in cusip_alpha, and copy the corresponding type value. @recode is not the way to do this. Basically, you need to manually go through every observation in scomp_cusp_al and search for a matching observation in cusip_alpha.

Code: Select all

series DS_s for !i = 1 to @obsrange if scomp_cusp_al(!i) <> "" then for !j = 1 to cusip_alpha.@last if scomp_cusp_al(!i) = cusip_alpha(!j) then DS_s(!i) = type(!j) !j = @obsrange endif next endif next

Re: @recode

Posted: Thu Jun 21, 2018 8:20 am
by shineK
Hi Matt,

i have another question that i need to create new columns ds_s_F/ds_c_F base on the ds_s/c_{%cntry}({%cntry}=a1, a2, dd1, dd2, dd3, dd4, dd5)
you may see the attached.
If one of ds_s/c_{%cntry} have 'value', ds_s/c_F = 'value', otherwise, = '0'
i not sure @recode command could use in this kind of issue, or not?

thanks a lot!!!

Re: @recode

Posted: Thu Jun 21, 2018 9:31 am
by EViews Matt
You want to examine values within each row, yes? For that @recode could work well. However, it's probably easier to use other EViews facilities. For example, you can add the series/columns you want to check to a group and then use @rfirst to identify the first non-NA value for each row of the group. Since your data appears to have only one unique non-NA value per row, identifying the first non-NA value matches what I believe you're requesting. Here's some sample code for ds_s_F,

Code: Select all

%names = @wcross("ds_s_", "a1 a2 " + @wcross("dd", "1 2 3 4 5")) group tmp {%names} ds_s_F = @nan(@rfirst(tmp), 0)

Re: @recode

Posted: Fri Jun 22, 2018 12:17 am
by shineK
Hi Matt,

Thank you so so so much~~~ :D

Re: @recode

Posted: Wed Jun 27, 2018 3:36 am
by shineK
Hi there,

i would like to do downsize within 2 files as attached.
and, create a new file that when obs = ds_s_F, and keep the obs.
how do i do it?
thanks!!!

Re: @recode

Posted: Wed Jun 27, 2018 9:17 am
by EViews Matt
It's unclear to me which observations you want to keep. Regardless, if you can create a dummy series indicating which observations you want to keep, you can then contract the workfile page using that series and save it as a new workfile.

Re: @recode

Posted: Wed Jun 27, 2018 9:33 am
by shineK
Hi Matt,

i would like to check whether the code in the 2nd pic exist in the column DS_S_F in the 1st pic
if not exist then drop the whole column of the code
for example,
if B1(867270) not exist in the DS_S_F, then drop the column

At the end, it will have a new file with the code that DS_S_F exist

i'm not sure you understand my explanation or not...?
:?:

Re: @recode

Posted: Wed Jun 27, 2018 10:04 am
by EViews Matt
I understand now, you want to eliminate columns (series), not observations. Once you've imported both files, you can go through each series name of the second file (using @wlookup) and see whether it is present in DS_S_F (similar to the code several posts ago) within the first file. If not, then delete the series.

Re: @recode

Posted: Wed Jun 27, 2018 10:56 am
by shineK
Hi Matt,

i just try to use @wlookup command, but im not quite sure the function.
i attached 2 files, please check. Thanks!!!

Re: @recode

Posted: Wed Jun 27, 2018 1:01 pm
by EViews Matt
Here's an example that gets you part way there. I'd forgotten that EViews will prepend "num" to numeric series names during an import, but that's easy to work around.

Code: Select all

wfopen CUSIP_FF_run.xlsx range=CUSIP_FF colhead=1 na="#N/A" @smpl @all wfopen Dret_Mret_test.xlsx range=ACT1_RET_F colhead=1 na="NA" @freq D5 @id @date(obs) @smpl @all copy CUSIP_FF_RUN::Cusip_ff_run\ds_s_f ds_s_f %all_series = @wlookup("num*") for %series {%all_series} !id = @val(@mid(%series, 4)) if @min(@abs(ds_s_f - !id)) <> 0 then delete %series endif next delete ds_s_f