Announcement

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

  • How to create percentages?

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long customer_id float platform
          35 1
          35 1
    10794785 3
    12407667 3
          35 1
          35 1
          35 1
          35 1
          35 1
     6834617 2
          35 1
     7280359 2
          35 1
    10893468 2
     1747974 2
    12093434 4
          35 1
     9821471 3
          35 1
     2676426 3
          35 1
          35 1
          35 1
          35 1
          35 1
          35 1
          35 1
     8139630 4
          35 1
          35 1
    12562025 3
          35 1
    11295091 2
    13108472 2
          35 1
          35 1
     9369267 3
          35 1
    11268838 2
     6344472 2
          35 1
          35 1
     7123191 2
    11725152 2
     4959683 2
          35 1
          35 1
          35 1
    11462866 2
     2730348 3
          35 1
          35 1
          35 1
    11872647 2
     9930565 4
          35 1
          35 1
     8404195 3
          35 1
          35 1
     9930565 4
          35 1
          35 1
          35 1
          35 1
          35 1
          35 1
          35 1
     1438304 2
          35 1
          35 1
          35 1
     9930565 4
     5490563 3
          35 1
     5454891 2
     3200165 4
    10484546 2
    11274718 2
          35 1
          35 1
          35 1
     9930565 4
    10038218 3
          35 1
     9369267 3
          35 1
     4621500 3
          35 1
     5863677 2
          35 1
          35 1
          35 1
     9930565 4
    11040634 3
          35 1
          35 1
          35 1
          35 1
          35 1
    end


    The variable customer_id represents unique customer id. The variable platform represents the platform through which an customer ordered food. I would like to create a variable which shows the percentage of orders through platform 1 with respect to customer_id. If the customer has not ordered through platform 1, then 0. How should I proceed to create the new variable?

  • #2
    Code:
    egen wanted = mean((platform==1) * 100), by(customer_id)

    Comment


    • #3
      Thanks! It worked

      Comment

      Working...
      X