Announcement

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

  • Finding out proportions by groups

    Hello everyone,

    I'm struggling with one piece of code and am hoping I can get some help here. I have a dataset where I have two variables: Firm ID and the areas it serves given by Area_Code. Each row in my dataset represents a customer served by the firm and I have multiple customers per area code. I want to calculate the percentage of customers served by a firm in each area_code. For example, the percent of customers of Firm 1 in area_code 001 and so on.

    I would really appreciate any ideas around this.

    Happy to answer any clarifications if my ask is not clear.

    Thank you in advance for any help!

  • #2
    Mansha, not sure if the code below fits your data.

    Code:
    bys Area_Code Firm_ID: gen n_customer = _N
    bys Area_Code: gen pct_customer = n_customer / _N * 100

    Comment


    • #3
      Yes, this helps! Thank you

      Comment

      Working...
      X