BookmarkSubscribeRSS Feed
namrata
Fluorite | Level 6

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.

14 REPLIES 14
Ksharp
Super User

Or SQL ?

proc sql;

create table want as

select gvkey,year,std(variable) as std

  from have

  group by gvkey,year

;

quit;

Ksharp

namrata
Fluorite | Level 6

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,


Reeza
Super User

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

Check your log.

namrata
Fluorite | Level 6

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.

ArtC
Rhodochrosite | Level 12

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?

namrata
Fluorite | Level 6

Yes ,there are atleast 2 obs against each id.

namrata
Fluorite | Level 6

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


ArtC
Rhodochrosite | Level 12

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;

namrata
Fluorite | Level 6

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.

ArtC
Rhodochrosite | Level 12

Let us know how it works for you.

ArtC
Rhodochrosite | Level 12

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

ArtC
Rhodochrosite | Level 12

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;

Ksharp
Super User

Arthur.Carpenter,

Long time no see.

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

Xia Keshan

ArtC
Rhodochrosite | Level 12

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 14 replies
  • 2403 views
  • 0 likes
  • 4 in conversation