Announcement

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

  • defining group numbers

    Dear All, I found this question here (https://bbs.pinggu.org/thread-7407152-1-1.html). The data is
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(x w)
    1 1
    2 1
    1 2
    2 2
    3 2
    1 3
    2 3
    3 3
    1 4
    2 4
    1 5
    1 6
    2 6
    end
    We have x variable (has been sorted), and want to define the group variable like w. Any suggestions?
    Ho-Chuan (River) Huang
    Stata 19.0, MP(4)

  • #2
    Code:
    generate long wstar = sum(x == 1)
    assert wstar == w
    Assumes values of x are representative, i.e., new groups all start at one.

    Comment


    • #3
      Dear Joseph, Many thanks for this wonderful suggestion.

      Ho-Chuan (River) Huang
      Stata 19.0, MP(4)

      Comment

      Working...
      X