Announcement

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

  • Generate variable of distinct users by month with daily data

    Hey Everyone,

    I have daily data on transactions from a point-of-sale system. I want to generate a variable that counts the number of distinct users who logged a transaction (who have a "user_id" in the system) by month and location. I am eventually going to collapse this data by month and want the value to carry over.

    What is the best way to accomplish this task?

    The idea maybe to do something like:

    ```
    by user_id location monthlydate, sort: gen nvals = _n == 1
    replace nvals = sum(nvals)
    replace nvals = nvals[_N]
    ```


    But I am not positive if this is what I want, and what is the best way to keep this value through the collapse code. Thank you in advance for your help! -Josh
    Last edited by josh scott; 06 Apr 2022, 11:09.

  • #2
    Perhaps the following will start you in a useful direction.
    Code:
    egen user = tag(monthlydate location userid)
    by monthlydate location, sort: egen nvals = total(user)

    Comment

    Working...
    X