Announcement

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

  • Index variable within two grouping variables

    Good afternoon, I am attempting to create an indexing variable that takes into account two variables (MATCHID and date). Below is an example of the variable "n" that I would like to create. I have tried a number of commands ("by MATCHID date: gen n = _n"; "sort MATCHID date" and then "by MATCHID: gen n = _n"; "egen n=group(MATCHID date)") but none get me to where: (a) the value of "n" is repeated when the date is repeated for a particular MATCHID, and (b) where the counter starts over at 1 for a new MATCHID.
    MATCHID n--what I want Date
    A1 1 8/18/2017
    A1 2 9/9/2017
    A1 3 10/14/2017
    A1 4 11/23/2018
    A1 5 6/5/2019
    A1 5 6/5/2019
    A1 6 7/4/2019
    A10 1 9/9/1999
    A10 2 1/14/2001
    A10 3 8/8/2004
    A10 4 7/17/2007
    I appreciate any guidance you can provide.
    Thank you,
    Jamie
Working...
X