DATA Step, Macro, Functions and more

match data find means

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 102
Accepted Solution

match data find means

Hi, all

My unit of analysis is firm-year. main interest is variable disclose (binary 0,1).

First, I will partition the sample into two sets : set ONE contains firm-year observations that have disclose=0, and  set TWO contains firm-year observations that have disclose=1,

What I want to know is : for set ONE observations that share the same industry code with set ONE observations, what is the mean value of disclose,

Similarly, for set TWO observations that share the same industry code with set ONE observations, what is the mean value of disclose,

that is, I try to show whether industry peers in set ONE are more or less likely to disclose compared with industry peers in set TWO.

What would be the best way of coding this? Attached is hypothetical data. Feel free to expand it.

Thanks!

firm

year

industry

disclose

a

2000

1

0

a

2001

1

0

a

2002

1

1

a

2003

1

1

b

2000

1

0

b

2001

1

1

c

2001

2

0

c

2002

2

1

c

2003

2

1

c

2004

2

1

d

2001

2

0

d

2002

2

1

d

2003

2

0

e

2001

2

0

e

2002

2

1

e

2003

2

1

e

2004

2

1

Lan


Accepted Solutions
Solution
‎09-02-2013 10:24 PM
Respected Advisor
Posts: 4,932

Re: match data find means

From the little I understand, I looks like you want to do this:

data test;
input firm $ year industry disclose;
datalines;
a 2000 1 0
a 2001 1 0
b 2000 1 0
c 2001 1 0
d 2001 2 0
d 2002 2 0
e 2001 2 0
a 2002 1 1
a 2003 1 1
b 2001 1 1
c 2000 1 1
c 2002 1 1
c 2003 1 1
c 2004 1 1
d 2002 2 1
e 2002 2 1
e 2003 2 1
e 2004 2 1
;

proc sql;
create table disc as
select t1.disclose, t1.industry, t1.firm, t1.year,
     mean(t2.disclose) as meanCompetitorDisclosure
from test as t1 left join test as t2
     on t1.year=t2.year and t1.industry=t2.industry and t1.firm ne t2.firm
group by t1.disclose, t1.industry, t1.firm, t1.year;

select * from disc;

quit;

proc ttest data=disc;
class disclose;
var  meanCompetitorDisclosure;
run;

PG

PG

View solution in original post


All Replies
Super User
Posts: 5,516

Re: match data find means

It sounds like splitting the data is too drastic a step.  For example, the mean DISCLOSE for any subset of ONE observations has to be 0.  And the mean DISCLOSE for any subset of TWO observations has to be 1.  Maybe a better starting point would be to create two summaries:  which industry codes have any DISCLOSE=0 observations, and which industry codes have any DISCLOSE=1 observations.  It's a little unclear to me whether that should be at the industry code level or the industry code + year level.  At any rate, if you were to take your sample data and show what numbers you would like to end up with, that would help.

Good luck.

Super Contributor
Posts: 297

Re: match data find means

Hi LanMin,

Is this what you are trying to achieve?

PROC MEANS DATA=HAVE NONOBS NOPRINT NWAY MISSING;

CLASS INDUSTRY;

VAR DISCLOSE;

OUTPUT OUT=WANT (DROP =_Smiley Happy MEAN=;

RUN;

Regards,

Scott

Frequent Contributor
Posts: 102

Re: match data find means

Posted in reply to Scott_Mitchell

thanks to both of you.

Scott, your code is not what I want exactly.

i paste my question again here, and give an example (see ********** in the end):

My unit of analysis is firm-year. main interest is variable disclose (binary 0,1).

First, I will partition the sample into two sets : set ONE contains firm-year observations that have disclose=0, and  set TWO contains firm-year observations that have disclose=1,

What I want to know is : for set ONE observations that share the same industry code with set ONE observations, what is the mean value of disclose,

Similarly, for set TWO observations that share the same industry code with set ONE observations, what is the mean value of disclose,

that is, I try to show whether industry peers in set ONE are more or less likely to disclose compared with industry peers in set TWO.

***************

example:

My original data would be partition into

disclose =0

firmyearindustrydisclose
a200010
a200110
b200010
c200110
d200120
d200220
e200120

disclose =1

firmyearindustrydisclose
a200211
a200311
b200111
c200011
c200211
c200311
c200411
d200221
e200221
e200321
e200421

for firm a in year 2000, industry=1, it has 2 competitors in year 2000, b and c, b's disclose=0 and c's disclose=1, so what I want is to output the average  disclose value of these two competitors as 0.5.

what I want as final results is a table with mean values in 2 cells below,

disclose =1disclose =0
peers average diclose value

then do a t-test  to see if peers are more or less likely to disclose in each subsample (i.e. disclose =1 vs. disclose =0 subset)..

thanks,

Lan

Solution
‎09-02-2013 10:24 PM
Respected Advisor
Posts: 4,932

Re: match data find means

From the little I understand, I looks like you want to do this:

data test;
input firm $ year industry disclose;
datalines;
a 2000 1 0
a 2001 1 0
b 2000 1 0
c 2001 1 0
d 2001 2 0
d 2002 2 0
e 2001 2 0
a 2002 1 1
a 2003 1 1
b 2001 1 1
c 2000 1 1
c 2002 1 1
c 2003 1 1
c 2004 1 1
d 2002 2 1
e 2002 2 1
e 2003 2 1
e 2004 2 1
;

proc sql;
create table disc as
select t1.disclose, t1.industry, t1.firm, t1.year,
     mean(t2.disclose) as meanCompetitorDisclosure
from test as t1 left join test as t2
     on t1.year=t2.year and t1.industry=t2.industry and t1.firm ne t2.firm
group by t1.disclose, t1.industry, t1.firm, t1.year;

select * from disc;

quit;

proc ttest data=disc;
class disclose;
var  meanCompetitorDisclosure;
run;

PG

PG
Frequent Contributor
Posts: 102

Re: match data find means

thanks so much PG !!

🔒 This topic is solved and locked.

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

Discussion stats
  • 5 replies
  • 257 views
  • 0 likes
  • 4 in conversation