Programming the statistical procedures from SAS

Standard Deviation and Rank Transformation

Accepted Solution Solved
Reply
Contributor
Posts: 65
Accepted Solution

Standard Deviation and Rank Transformation

Hello SAS Support Communities, 

I have attached dataset comp16f.  Please send me a code I can use to do the following:
1. Standard deviation of ib1 for three years at a time.  Ib1 is the current year, lag1 is the prior year, and lag2 is two years before.  These are already included for each observation.
2. Rank transform the variable created in step 1 between 0 and 1.
 
Thank you so much in advance for your help!
 
God bless, best regards, and take care,
Jadallah
Attachment

Accepted Solutions
Solution
‎03-10-2018 09:17 PM
Respected Advisor
Posts: 3,040

Re: Standard Deviation and Rank Transformation

[ Edited ]

 

Ib1 is the current year, lag1 is the prior year, and lag2 is two years before.  These are already included for each observation.

 

I cannot open your zip file with the data, so I am going by the description of the data you stated and which I have quoted above. PROC EXPAND would work if you have each value of the three years in separate rows. But you state that the values you need are included for each observation. Thus, you need the STD function. Something like:

 

_3year_std = std(lb1,lag1,lag2);
--
Paige Miller

View solution in original post


All Replies
Respected Advisor
Posts: 3,040

Re: Standard Deviation and Rank Transformation

[ Edited ]

Instead of asking for code, you need to try to do this yourself, and if you can't get it, post your code so we can help you fix it.

 

Standard deviations are simple to compute in SAS, using data step or PROC SUMARY; and rank transformations can be done with PROC RANK.

--
Paige Miller
Contributor
Posts: 65

Re: Standard Deviation and Rank Transformation

Posted in reply to PaigeMiller

Hi Paige,

Thank you for your response.  I tried the following code:

PROC EXPAND DATA=dissert1.comp16f OUT=dissert1.comp16g;
CONVERT ib1=std / TRANSFORMOUT=(MOVSTD 3);
by gvkey;
RUN;

 

I would expect results to only show for firms that have a minimum of three observations.  However, there are values for firms with two observations.  What do you think?

 

God bless, best regards, and take care,

Jadallah 

Solution
‎03-10-2018 09:17 PM
Respected Advisor
Posts: 3,040

Re: Standard Deviation and Rank Transformation

[ Edited ]

 

Ib1 is the current year, lag1 is the prior year, and lag2 is two years before.  These are already included for each observation.

 

I cannot open your zip file with the data, so I am going by the description of the data you stated and which I have quoted above. PROC EXPAND would work if you have each value of the three years in separate rows. But you state that the values you need are included for each observation. Thus, you need the STD function. Something like:

 

_3year_std = std(lb1,lag1,lag2);
--
Paige Miller
Contributor
Posts: 65

Re: Standard Deviation and Rank Transformation

Posted in reply to PaigeMiller

Thank you again Paige!

I got the same answer with the following three codes:

PROC EXPAND DATA=dissert1.comp16f OUT=dissert1.comp16h;
CONVERT ib1=std / TRANSFORMOUT=(MOVSTD 3);
by gvkey;
RUN;

 

proc sql;
create table dissert1.comp16g as
select *,(select std(ib1) from dissert1.comp16f where fyear between a.fyear-2 and a.fyear and gvkey=a.gvkey) as rolling_std
from dissert1.comp16g as a;
quit;

 

data dissert1.comp16f1;
set dissert1.comp16f;
_3year_std = std(ib1,lag1,lag2);
run;

 

For proc rank, I did the following:

proc rank data=dissert1.comp16g out=dissert1.comp16h;
var _3year_std;
ranks Finish;
run;

 

How would I convert the finish variable from 0 to 1?

Respected Advisor
Posts: 3,040

Re: Standard Deviation and Rank Transformation

In PROC RANK, use the GROUPS=100 option. This gives numbers on the 0 to 100 scale. 

--
Paige Miller
Contributor
Posts: 65

Re: Standard Deviation and Rank Transformation

Posted in reply to PaigeMiller

Great job Paige!  Thank you so much for your help!  God bless you and your family!

Jadallah

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 150 views
  • 0 likes
  • 2 in conversation