@recode
Moderators: EViews Gareth, EViews Jason, EViews Moderator, EViews Matt
-
- Posts: 52
- Joined: Mon Nov 18, 2013 9:09 am
@recode
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
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
-
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13319
- Joined: Tue Sep 16, 2008 5:38 pm
Re: @recode
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)
Follow us on Twitter @IHSEViews
Re: @recode
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!!!!
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!!!!
- Attachments
-
- 900A_Act1_Cusp_test.csv
- (66.38 KiB) Downloaded 9230 times
-
- 900a_cusip.prg
- (1.59 KiB) Downloaded 9095 times
-
- SP500_cusp_s.csv
- (316.31 KiB) Downloaded 9143 times
Best,
SK
SK
-
- EViews Developer
- Posts: 563
- Joined: Thu Apr 25, 2013 7:48 pm
Re: @recode
Hello,
You could use something like,
and then add DS_s to group Scusp afterword.
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
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!!!!!!!
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!!!!!!!
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
- Attachments
-
- recode command.JPG (217.66 KiB) Viewed 37417 times
Best,
SK
SK
-
- EViews Developer
- Posts: 563
- Joined: Thu Apr 25, 2013 7:48 pm
Re: @recode
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
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!!!
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!!!
- Attachments
-
- 擷取.JPG (249.55 KiB) Viewed 37344 times
Best,
SK
SK
-
- EViews Developer
- Posts: 563
- Joined: Thu Apr 25, 2013 7:48 pm
Re: @recode
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
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!!!
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!!!
- Attachments
-
- ds
- 02.JPG (162.73 KiB) Viewed 37218 times
-
- return code
- 01.JPG (215.51 KiB) Viewed 37218 times
Best,
SK
SK
-
- EViews Developer
- Posts: 563
- Joined: Thu Apr 25, 2013 7:48 pm
Re: @recode
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
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...?
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...?
Best,
SK
SK
-
- EViews Developer
- Posts: 563
- Joined: Thu Apr 25, 2013 7:48 pm
Re: @recode
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
Hi Matt,
i just try to use @wlookup command, but im not quite sure the function.
i attached 2 files, please check. Thanks!!!
i just try to use @wlookup command, but im not quite sure the function.
i attached 2 files, please check. Thanks!!!
- Attachments
-
- Dret_Mret_test.xlsx
- (35.03 MiB) Downloaded 9130 times
-
- CUSIP_FF_run.xlsx
- DS_S_F
- (53.69 KiB) Downloaded 9182 times
Best,
SK
SK
-
- EViews Developer
- Posts: 563
- Joined: Thu Apr 25, 2013 7:48 pm
Re: @recode
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
Who is online
Users browsing this forum: No registered users and 34 guests