Date: Sat, 28 Apr 2007 23:22:28 -0400 "Howard Schreier " "SAS(r) Discussion" "Howard Schreier " Re: Changes and frequency of changes

On Sat, 28 Apr 2007 15:08:15 -0400, mcolowasth@YAHOO.CO.UK wrote:

>Hi, > >I observe variable x over time (from 1999-2005) for a large number of >firms, w. I have computed the change in variable x from one year to the >next. > >Now, I would like to identify whether variable x has changed from one year >to the next for each firm as well as how often it changed for each firm(in >some cases I expect no change in this variable i.e. 0). > >Any suggestions on how to do this in sas? > >Thanks

Generate test data, since original poster did not provide it:

data observed; do firm = 'a', 'b'; do year = 1999 to 2005; x = 2 + round(ranuni(135),0.3); output; end; end; run;

Result:

Obs firm year x

1 a 1999 2.9 2 a 2000 2.9 3 a 2001 2.9 4 a 2002 2.0 5 a 2003 2.3 6 a 2004 2.9 7 a 2005 2.3 8 b 1999 2.9 9 b 2000 2.6 10 b 2001 2.9 11 b 2002 2.6 12 b 2003 2.6 13 b 2004 2.3 14 b 2005 2.0

Here is a solution with a couple of dorfmanic touches:

data whether (keep = firm year x whether) howoften (keep = firm howoften) ; set observed; by firm; changed = not not dif(fuzz(x) ); if first.firm then howoften = 0; else do; whether = changed; howoften ++ changed; end; output whether; if last.firm then output howoften; run;

The formula for CHANGED first quantifies any difference, then the double boolean negation maps zero to zero and anything else to one.

WHETHER:

Obs firm year x whether

1 a 1999 2.9 . 2 a 2000 2.9 0 3 a 2001 2.9 0 4 a 2002 2.0 1 5 a 2003 2.3 1 6 a 2004 2.9 1 7 a 2005 2.3 1 8 b 1999 2.9 . 9 b 2000 2.6 1 10 b 2001 2.9 1 11 b 2002 2.6 1 12 b 2003 2.6 0 13 b 2004 2.3 1 14 b 2005 2.0 1

HOWOFTEN:

Obs firm howoften

1 a 4 2 b 5

Back to: Top of message | Previous page | Main SAS-L page