Announcement

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

  • How to generate categories by category

    Dear Statalist,

    Not sure if I am missing something obvious in -egen-, but I couldn't figure out an easy way to do the following task:


    Code:
    clear
    input str20 cat_A str20 cat_B
    S1 C1
    S1 C2
    S2 C6
    S2 C8
    S3 C10
    S3 C22
    S3 C93
    end
    I would like to have as a result this:


    cat_A cat_B cat_C
    S1 C1 1
    S1 C2 2
    S2 C6 1
    S2 C8 2
    S3 C10 1
    S3 C22 2
    S3 C93 3



    Thank you in advance for any tips.

    All the best,

    Tiago







  • #2
    Code:
    sort cat_A cat_B
    by cat_A: gen cat_C = _n

    Comment


    • #3
      Thank you so much, Friedrich. It worked like a charm.

      All the best,

      Tiago

      Comment

      Working...
      X