Announcement

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

  • Generating a variable by id and month

    Hi all,

    I tried the following code:

    bys screener_ssn_nbr (date_num): egen count_screenin_screener=count(call_accept==1)

    Basically, I want something that counts how many times call_accept=1 by each date for an individual with a certain id. However, this code doesn't quite work. (Call_accept is a 0 or 1 variable). This code seems to count how many times call_accept occurs (0 or 1) and doesn't even count it for the date specifically, does it in total.
    CAn you assist?
    Thanks!

  • #2
    If you think about it some more, you get this by summing. The only way you get 3 with 0/1 values is if you have 1+1+1, irrespective of how many zeros there are. So

    Code:
    bys screener_ssn_nbr (date_num): egen count_screenin_screener=total(call_accept)


    Comment


    • #3
      Andrew Musau explains what you need perfectly. Why did your code not work? As documented the count() function of egen counts how often its argument — what you feed it — is not missing; whether your argument is 0 because the evaluation returns false or 1 because it returns true, it is not missing either way. So the function just counts observations for individuals.

      Comment


      • #4
        You should get into the habit of presenting sample data using -dataex- when asking such questions, and explaining what results you desire with a reference to this sample data.

        I do not understand currently what you want from your verbal description, however I think that

        Code:
         
         bys screener_ssn_nbr (date_num): egen count_screenin_screener=total(call_accept)
        is superfluous.

        The command is equivalent (I think) to

        Code:
         
         bys screener_ssn_nbr: egen count_screenin_screener=total(call_accept)


        Comment


        • #5
          Thanks so much all! Yes, Joro you seem to be right....the command
          bys screener_ssn_nbr (date_num): egen count_screenin_screener=total(call_accept) Seems to just be counting how many calls are done over time. It is counting both call_accept=1 and call_accept=0.....and not doing it by the month. Not sure why?

          Comment


          • #6
            ----------------------- copy starting from the next line -----------------------
            Code:
            * Example generated by -dataex-. To install: ssc install dataex
            clear
            input str7 screener_ssn_nbr float(modate call_accept)
            "" 659 0
            "" 659 0
            "" 659 0
            "" 659 0
            "" 659 0
            "" 659 0
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 0
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 0
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            "" 660 1
            end
            format %tm modate

            Comment


            • #7
              If "screener_ssn_nbr" is your identifier, why is it missing?

              Code:
              bys screener_ssn_nbr modate: egen wanted= total(call_accept)

              Comment

              Working...
              X