Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to create a proportion that counts a dummy variable =1 relative to the sum of (variable=1+variable=0)?

    I have a set of firms that making a decision. I have a dummy variable called decision, it equals 1 if the firm made such a decision, and equals 0 if the decision is not made. I want to know the proportion of decision =1 relative to the sum of the entire sample (i.e., decision=1+decision=0), let's call it decision_prop. I also have another variable defining which industry each firm is in, how can I calculate decision_prop by industry?

    Thanks a lot!

  • #2
    As the variable is coded 0/1, the mean of the variable is the proportion that you desire. For example, if you have 4 values: 0, 0, 1, and 1, the mean is (0+0+1+1/4)= 0.5, precisely the proportion of ones. So check out

    Code:
    help egen
    To do this by industry, use the bysort prefix

    Code:
    help bysort
    So something like:

    Code:
    egen wanted1= mean(dummy)
    bysort industry: egen wanted2= mean(dummy)

    Comment


    • #3
      Hi Andrew,
      Thanks for your help! It works

      Cheers,
      Flora

      Comment

      Working...
      X