Hello
Could anybody tell me how to compute std dev of a variable in panel data?Is this right?
data want;
set have;
by gvkey year;
vol=std(variable);
run;
I tried this but the error is:
The STD function call does not have enough arguments.
thanks.
Or SQL ?
proc sql;
create table want as
select gvkey,year,std(variable) as std
from have
group by gvkey,year
;
quit;
Ksharp
Thanks Ksharp & ArtC.
I tried the code:
proc sql;
create table want as;
select gvkey, year, std(ni) as std
from final1
group by gvkey,year;
quit;
The std column remains blank,
you have an extra semi colon after the as in your first line after proc sql.
Check your log.
Sorry Reeza...that was a typo.I was not being able to copy my code directly from SAS.
There is no semi colon in that line.The table want is created with gvkeys & years...however std values are missing.
Silly question but can you verify that there are at least two values of NI for each combination of your GROUPBY variables, and that NI is not missing for at least two obs within the BY group?
Yes ,there are atleast 2 obs against each id.
I need to change my requirement a little..Want the std dev upto the previous year,essentially the lag std dev. Could anybody please help me with this?
Id year ni std
1 2000 5 -
1 2001 1 std(ni upto 2000)
1 2002 2 std(ni upto 2001)
1 2003 3 std(ni upto 2002)
2 2001 2 -
2 2002 5 std(ni upto 2001)
2 2003 5 std(ni upto 2002)
2 2004 1 std(ni upto 2003)
3 2002 6
3 2003 6
3 2004 4
In your revised problem I will assume that the column NI is the mean of the NI values. This problem is a form of a running average problem. I will tackle it here using a multlabel format - there are other approaches. In the following code substitute SEX AGE and WEIGHT for your variables the approach will be the same.
proc sort data=sashelp.class out=have;
by sex age;
run;
proc print data=have; run;
proc format ;
value yrgrp (multilabel)
10 = '10'
10-11 = '10-11'
10-12 = '10-12'
10-13 = '10-13'
10-14 = '10-14'
10-15 = '10-15'
10-16 = '10-16'
10-17 = '10-17'
10-18 = '10-18';
run;
proc summary data=have;
class sex;
class age/mlf;
var weight;
ways 2;
output out=groups n= mean= std=/autoname;
format age yrgrp.;
run;
proc print data=groups; run;
ArtC, I am so sorry for this late reply. I have not been able to try out the suggestion since I have a submission soon and I decided to try out the code for the extensive paper that I shall work on after the submission.
I apologize once again & thank you so much for writing out the code for me.I shall definitely try it out and get back to you.
Let us know how it works for you.
Are you still getting missing values for the STD? My test code gives the expected results.
The SUMMARY procedure, among others, will also provide univariate summary statistics.
proc summary data=have;
class gvkey year;
var variable;
output out=summry /autoname;
run;
Arthur.Carpenter,
Long time no see.
Maybe you miss NWAY option ,since OP don't want all levels of class variables.
Xia Keshan
Thanks Ksharp - good catch. Or the WAYS statement which offers more flexibility.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.