Announcement

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

  • Help create a new variable

    Hello Statalist Forum,

    The following extracted data indicates different focus area employees of a sample organization are staffed to. I am interested in creating a new variable that identifies employees that are currently staffed to two or more focus areas.

    Would appreciate any insights on how to generate this variable! Ideally candidates staffed to more than one focus area would be coded as 1 and candidates who are staffed to left than 1 would be coded as 0.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte(focus_area_1 focus_area_2 focus_area_3 focus_area_4 focus_area_5)
    . . . 1 .
    . . . . .
    . . 1 . .
    . . . . .
    1 . . 1 .
    . . . 1 .
    . . . . .
    . . . . .
    1 1 . . .
    . . . . .
    . . . . .
    . . . . .
    . . . 1 .
    . . . . .
    . . . . .
    . . . . .
    . . . 1 1
    . . . . 1
    1 . . . .
    1 . . . .
    . . . . .
    . . . . .
    . . . 1 .
    . 1 . 1 .
    . . . . .
    . . . . .
    . . . . .
    . . . . .
    . . . . .
    . . . . .
    . . . . .
    . . . . .
    . . . . .
    . . . . .
    1 . . . .
    . . . . .
    . . . . .
    . . . 1 .
    . . . . .
    . . 1 . .
    . . . . .
    . . 1 . .
    . . . . .
    . . . . .
    . . . 1 .
    . . 1 . .
    . . . 1 .
    . . . . .
    . . . 1 .
    1 . . 1 .
    . . . . .
    . . . . .
    1 1 . 1 .
    . . . . .
    . . . . .
    . . . . .
    . 1 1 . .
    . . . . .
    1 . . . 1
    . . . . .
    . . . . .
    . . . . .
    . . . 1 .
    . . 1 . .
    . . . . .
    . . . . .
    . . . 1 .
    . . . . .
    . . . . .
    . . . . .
    . . . . .
    . . . . .
    . . . 1 .
    . . . . .
    . . . . .
    . . . . .
    1 . . . .
    . . . . .
    . . . 1 .
    . . . . .
    . . . . .
    . . . 1 .
    . . . . .
    . . . . .
    . . . . .
    . . . . .
    . . . 1 .
    . . . 1 .
    1 . . . .
    . . . . .
    . . . 1 .
    . . . . .
    . . 1 . .
    . . . . .
    . . . . .
    . . 1 . .
    . . . . .
    . 1 . 1 .
    end

  • #2
    You can start with egen function anycount() or even rowtotal() just to count 1s across your variables.

    I can't follow your intended coding. More than 1 maps to 1, "left than 1" looks like a typo for "less than 1" and that maps to 0. What about is equal to 1?

    Comment


    • #3
      Originally posted by Nick Cox View Post
      You can start with egen function anycount() or even rowtotal() just to count 1s across your variables.

      I can't follow your intended coding. More than 1 maps to 1, "left than 1" looks like a typo for "less than 1" and that maps to 0. What about is equal to 1?
      Hello Nick,

      Apologies for the confusion. To clarify, I am looking to create a dummy variable for employees staffed on more than one focus area and people staffed only to one focus area. So adding the entires would not be ideal since I would want to create a dummy variable where 1 maps to employees staffed to more than one focus area and 0 maps to employees staffed to only 1 (or 0). Any suggestions on how to achieve this?

      Comment


      • #4
        As I said, you can start with either function. How you then map to your desired variable depends on your coding, which you have now clarified.

        Getting rid of the duplicates in your data example as just variations on existing patterns, this should get you nearer to where you want to be.

        Code:
        * Example generated by -dataex-. For more info, type help dataex
        clear
        input byte(focus_area_1 focus_area_2 focus_area_3 focus_area_4 focus_area_5)
        . . . 1 .
        . . . . .
        . . 1 . .
        1 . . 1 .
        1 1 . . .
        . . . 1 1
        . . . . 1
        1 . . . .
        . 1 . 1 .
        1 1 . 1 .
        . 1 1 . .
        1 . . . 1
        end
        
        
        . egen count = rowtotal(focus_area_?)
        
        . gen wanted = count > 1
        
        . sort wanted count
        
        . list, sepby(wanted)
        
             +-----------------------------------------------------------------------+
             | focus_~1   focus_~2   focus_~3   focus_~4   focus_~5   count   wanted |
             |-----------------------------------------------------------------------|
          1. |        .          .          .          .          .       0        0 |
          2. |        1          .          .          .          .       1        0 |
          3. |        .          .          .          .          1       1        0 |
          4. |        .          .          .          1          .       1        0 |
          5. |        .          .          1          .          .       1        0 |
             |-----------------------------------------------------------------------|
          6. |        .          .          .          1          1       2        1 |
          7. |        .          1          1          .          .       2        1 |
          8. |        1          1          .          .          .       2        1 |
          9. |        1          .          .          .          1       2        1 |
         10. |        1          .          .          1          .       2        1 |
         11. |        .          1          .          1          .       2        1 |
         12. |        1          1          .          1          .       3        1 |
             +-----------------------------------------------------------------------+

        Comment

        Working...
        X