Announcement

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

  • how to create a cross-tabulation, dummy variables and regression with wide data

    Can someone help me a syntax to use on how to i run cross tabulations, create dummy variables and run a regression with a wide format dataset in stata.

  • #2
    The experienced users here generally agree that, with few exceptions, Stata makes it much more straightforward to accomplish complex analyses using a long layout of your data rather than a wide layout of the same data.

    In the example below I have created example data based on what you showed in your earlier topic, and I demonstrate how to reshape it to a long layout.
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input double uniqueid str6 hhrostersex1 byte hhrosteryr1 str6 hhrostersex2 byte hhrosteryr2 str6 hhrostersex3 byte hhrosteryr3
    99036174101 "Female" 49 "Male"   54 "Male"   20
    99036174111 "Female" 58 "Male"   63 ""        .
    99036174121 "Female" 23 "Male"   23 "Female" 43
    99036174131 "Female" 30 ""        . ""        .
    99036174132 "Female" 23 "Male"   30 "Male"    4
    99036174151 "Male"   46 "Female" 41 ""        .
    99036174161 "Female" 38 "Male"   43 ""        .
    99036174171 "Male"   63 ""        . ""        .
    99036174191 ""        . ""        . ""        .
    end
    reshape long hhrostersex hhrosteryr, i(uniqueid) j(person)
    drop if missing(hhrostersex) & missing(hhrosteryr)
    sort uniqueid person
    format uniqueid %11.0f
    list, sepby(uniqueid) abbreviate(12)
    Code:
    . list, sepby(uniqueid) abbreviate(12)
    
         +-------------------------------------------------+
         |    uniqueid   person   hhrostersex   hhrosteryr |
         |-------------------------------------------------|
      1. | 99036174101        1        Female           49 |
      2. | 99036174101        2          Male           54 |
      3. | 99036174101        3          Male           20 |
         |-------------------------------------------------|
      4. | 99036174111        1        Female           58 |
      5. | 99036174111        2          Male           63 |
         |-------------------------------------------------|
      6. | 99036174121        1        Female           23 |
      7. | 99036174121        2          Male           23 |
      8. | 99036174121        3        Female           43 |
         |-------------------------------------------------|
      9. | 99036174131        1        Female           30 |
         |-------------------------------------------------|
     10. | 99036174132        1        Female           23 |
     11. | 99036174132        2          Male           30 |
     12. | 99036174132        3          Male            4 |
         |-------------------------------------------------|
     13. | 99036174151        1          Male           46 |
     14. | 99036174151        2        Female           41 |
         |-------------------------------------------------|
     15. | 99036174161        1        Female           38 |
     16. | 99036174161        2          Male           43 |
         |-------------------------------------------------|
     17. | 99036174171        1          Male           63 |
         +-------------------------------------------------+

    Comment


    • #3
      i have over 200variables

      Comment

      Working...
      X