Announcement

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

  • Generate data set using cross tabulation cell frequency

    Dear all,
    Is it possible to generate data set include two variable using cross tabulation cell frequency
    exposed unexposed Total
    case 6 50 56
    noncases 33 94 127
    total 39 144 183

    Thanks so much for any of your help

    Regards
    Suga
    Last edited by suganthiny kumarasamy; 29 Jul 2022, 17:14.

  • #2
    your question is not completely clear to me but I think you want the following options to tabulate: matcell, matrow, matcol; see
    Code:
    help tabulate twoway

    Comment


    • #3
      Thanks Rich Goldstein for your quick reply
      I want to generate
      Y variable has 2 level, 1= exposed, 0= unexposed
      X variable has 2 level, 1=case, 0= noncases
      I want to generate x and y variable contained 0 and 1 when I cross tabulate x and y , I should have save freq as the cross table I mention above.


      set obs 183
      egen m =seq(), f(1) b(56)
      egen m_6 =seq(), f(0) b(127)
      replace m=0 if m~=1
      drop m_6

      egen sex_0=seq(), f(0) b(144)
      egen sex_1=seq(), f(1) b(39)
      replace sex_1=0 if sex_1~=1
      replace sex_1=0,
      i don't know how to do it after that
      Last edited by suganthiny kumarasamy; 29 Jul 2022, 17:29.

      Comment


      • #4
        Consider this automatic side-effect of tabi

        Code:
        . clear
        
        . tabi 6 50 \ 33 94
        
                   |          col
               row |         1          2 |     Total
        -----------+----------------------+----------
                 1 |         6         50 |        56 
                 2 |        33         94 |       127 
        -----------+----------------------+----------
             Total |        39        144 |       183 
        
                   Fisher's exact =                 0.020
           1-sided Fisher's exact =                 0.014
        
        . d
        
        Contains data
         Observations:             4                  
            Variables:             3                  
        --------------------------------------------------------------------------------------------------------------
        Variable      Storage   Display    Value
            name         type    format    label      Variable label
        --------------------------------------------------------------------------------------------------------------
        row             byte    %8.0g                 
        col             byte    %8.0g                 
        pop             long    %12.0g                
        --------------------------------------------------------------------------------------------------------------
        Sorted by: 
             Note: Dataset has changed since last saved.
        
        . l
        
             +-----------------+
             | row   col   pop |
             |-----------------|
          1. |   1     1     6 |
          2. |   1     2    50 |
          3. |   2     1    33 |
          4. |   2     2    94 |
             +-----------------+
        Now use rename, label and even expand to taste.

        Comment


        • #5
          Thanks so much Nick Cox.

          Comment

          Working...
          X