Help using Base SAS procedures

Standard deviation in panel data

Reply
Contributor
Posts: 52

Standard deviation in panel data

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.

Super User
Posts: 10,035

Re: Standard deviation in panel data

Or SQL ?

proc sql;

create table want as

select gvkey,year,std(variable) as std

  from have

  group by gvkey,year

;

quit;

Ksharp

Contributor
Posts: 52

Re: Standard deviation in panel data

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,


Super User
Posts: 19,822

Re: Standard deviation in panel data

you have an extra semi colon after the as in your first line after proc sql.

Check your log.

Contributor
Posts: 52

Re: Standard deviation in panel data

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.

Valued Guide
Posts: 634

Re: Standard  deviation in panel data

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?

Contributor
Posts: 52

Re: Standard  deviation in panel data

Yes ,there are atleast 2 obs against each id.

Contributor
Posts: 52

Re: Standard  deviation in panel data

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


Valued Guide
Posts: 634

Re: Standard  deviation in panel data

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;

Contributor
Posts: 52

Re: Standard  deviation in panel data

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.

Valued Guide
Posts: 634

Re: Standard  deviation in panel data

Let us know how it works for you.

Valued Guide
Posts: 634

Re: Standard  deviation in panel data

Are you still getting missing values for the STD?  My test code gives the expected results.

Valued Guide
Posts: 634

Re: Standard deviation in panel data

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;

Super User
Posts: 10,035

Re: Standard deviation in panel data

Arthur.Carpenter,

Long time no see.

Maybe you miss NWAY option ,since OP don't want all levels of class variables.

Xia Keshan

Valued Guide
Posts: 634

Re: Standard deviation in panel data

Thanks Ksharp - good catch.  Or the WAYS statement which offers more flexibility.

Ask a Question
Discussion stats
  • 14 replies
  • 949 views
  • 0 likes
  • 4 in conversation