Announcement

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

  • combination of numeric & string variable

    Dear all,

    As you can see, I have 2 variables, namely id and person. I want to create a third variable (i.e. reference_id) that counts how many of the same id occurs for a particular person.
    I've used egen reference_id= count (id), by (person), however, this gives me an error because the variable id is a combination of numeric and strings. Can somebody give me feedback, please? I've tried destring as well but it gives me also an error.

    This is the result I would like to have:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str3 ID str1 Person byte reference_id
    "O78" "A" 2
    "P34" "A" 1
    "M98" "A" 1
    "O78" "A" 2
    end
    Thank you in advance!
    Last edited by Glenda C; 28 Apr 2017, 05:28.

  • #2
    Code:
    * ??? 
    bysort ID Person : gen wanted = _N

    Comment


    • #3
      Dear Nick,

      Thank you so much and I'm sorry for the inconvenience ( I am a recent STATA user, hence, I'm not quite familiar with it).

      Comment


      • #4
        Asking questions is not an inconvenience!

        Comment

        Working...
        X