Announcement

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

  • count problem

    Dear all

    i want to generate new var that count P1_3 ==3 (means child) , and i write a code but stata tell me unknown egen function count()

    my code : egen byte new1 = count (P1_3) if (P1_3 == 3) , by (HOUS)

    thanks!!
    Attached Files

  • #2
    and i also want to generate 2 new var
    1. child is male
    2. child is female

    and my code is
    keep P1_3 if P1_3 == 3
    egen new2 = count (P1_4) if P1_4 == 1 , by (HOUS)
    egen new3 = count (P1_4) if P1_4 == 2 , by (HOUS)

    but it doesn't work....

    Comment


    • #3
      It is not clear why you would get an error with the command in post #1. In post #2 the first command should be
      Code:
      keep if P1_3 == 3
      The count() function of egen is not the right choice for your problem because it counts all non-missing observations. Instead, use the total() function.
      Code:
      bysort HOUS: egen new2 = total(P1_4==1)
      For future reference, please read section 12 in the FAQ and show exactly what you typed and exactly what Stata typed (or did) in response. Do not just say "it doesn't work." Please use CODE tags for Stata commands. For sharing data you can use the dataex package.

      Comment


      • #4
        in post #1

        #code
        egen new1 = count(P1_3) if P1_3 == 3 , by (HOUS)


        but the result is :
        HOUS new1
        1 1616
        1 1616
        it should be
        HOUS new1
        1 2
        1 2

        Comment


        • #5
          Did you try the egen command in post #3?

          Comment

          Working...
          X