Calculate percentage by firm and year

Accepted Solution Solved
Reply
Contributor
Posts: 29
Accepted Solution

Calculate percentage by firm and year

Hi,

 

Could you help me figure out how to calculate percentage by firm and year?

 

My data looks like... 

 

data test;

input firm year director dummy;

datalines;

1001 2000 aaa 0

1001 2000 bbb 0

1001 2000 ccc 1

1001 2000 ddd 0

1001 2001 aaa 0

1001 2001 bbb 0 

1001 2001 ccc 1

1001 2001 ddd 0

1001 2001 eee 0

1002 2005 fff 1

1002 2005 ggg 1

1002 2005 hhh 0

1002 2005 iii 0

1002 2006 fff 1

1002 2006 ggg 0

1002 2006 hhh 1

1002 2006 iii 0

1002 2006 jjj 1

;

run;

 

I need to get a column (Percentage_MD) having the percentage of MD by firm and year.

 

Thank you!


Accepted Solutions
Solution
‎03-14-2018 11:50 PM
Super User
Posts: 23,777

Re: Calculate percentage by firm and year

And the percentage is calculated how? If it sum of 1 over count of all obs then just use PROC MEANS since the average of a binary variable is the same as the percent. 

 

proc means data=have mean;
by firm year;
var dummy;
run;

View solution in original post


All Replies
Super User
Posts: 23,777

Re: Calculate percentage by firm and year

How is this column being calculated? You have no variable named MD? Percentage of what...

 


@hkim3677 wrote:

Hi,

 

Could you help me figure out how to calculate percentage by firm and year?

 

My data looks like... 

 

data test;

input firm year director dummy;

datalines;

1001 2000 aaa 0

1001 2000 bbb 0

1001 2000 ccc 1

1001 2000 ddd 0

1001 2001 aaa 0

1001 2001 bbb 0 

1001 2001 ccc 1

1001 2001 ddd 0

1001 2001 eee 0

1002 2005 fff 1

1002 2005 ggg 1

1002 2005 hhh 0

1002 2005 iii 0

1002 2006 fff 1

1002 2006 ggg 0

1002 2006 hhh 1

1002 2006 iii 0

1002 2006 jjj 1

;

run;

 

I need to get a column (Percentage_MD) having the percentage of MD by firm and year.

 

Thank you!


 

 

 

Contributor
Posts: 29

Re: Calculate percentage by firm and year

Oh sorry,

 

Dummy column is MD.

 

 

Solution
‎03-14-2018 11:50 PM
Super User
Posts: 23,777

Re: Calculate percentage by firm and year

And the percentage is calculated how? If it sum of 1 over count of all obs then just use PROC MEANS since the average of a binary variable is the same as the percent. 

 

proc means data=have mean;
by firm year;
var dummy;
run;
Contributor
Posts: 29

Re: Calculate percentage by firm and year

Sorry, I should have been clearer.

My question here is how to create the column containing the percentage of manager having MD=1 by firm and year.

 

Super User
Posts: 23,777

Re: Calculate percentage by firm and year

Then my previous answer was correct. 

 


@hkim3677 wrote:

Sorry, I should have been clearer.

My question here is how to create the column containing the percentage of manager having MD=1 by firm and year.

 


 

☑ This topic is solved.

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

Discussion stats
  • 5 replies
  • 140 views
  • 0 likes
  • 2 in conversation