Announcement

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

  • extracting estimates from a twoway tabulation

    How do I extract estimates from a two way tabulation in stata?

    Example data:
    Code:
    clear all
    set obs 100
    gen id=_n
    gen x = runiform()
    gen xx=(x>0.5)
    gen y = runiform() + 1
    gen yy =(y>1.7)
    gen z = runiform()
    gen zz = 0
    replace zz = 1 if (z>0.3 & z<0.7)
    replace zz = 2 if z>0.6
    tab xx yy, col nokey
    tab yy zz, col nokey
    tab xx yy, col nokey

    Code:
            yy
        xx    0    1    Total
                        
        0    38    15    53 
            54.29    50.00    53.00 
                        
        1    32    15    47 
            45.71    50.00    47.00 
                        
        Total    70    30    100 
            100.00    100.00    100.00

    . tab yy zz, col nokey

    Code:
             zz
        yy    0    1    2    Total
                        
        0    19    18    33    70 
            79.17    72.00    64.71    70.00 
                        
        1    5    7    18    30 
            20.83    28.00    35.29    30.00 
                        
        Total    24    25    51    100 
            100.00    100.00    100.00    100.00

    I want to plot a twoway line graph or something closer of (xx and yy), and also (yy and zz) and use addplot to plot this two on same scale(or graph)

    I noticed after -return list- command that these estimates are not stored. Does any one have information on any trick or user written command that I use to extract this estimates?

    Thanks in anticipation.

  • #2
    Consider

    1. the matcell() option of tabulate.

    2. calculating frequencies directly.

    Code:
    . tab yy zz, col nokey  matcell(freq)
    
               |          zz
            yy |         0          1 |     Total
    -----------+----------------------+----------
             0 |        41         27 |        68
               |     69.49      65.85 |     68.00
    -----------+----------------------+----------
             1 |        18         14 |        32
               |     30.51      34.15 |     32.00
    -----------+----------------------+----------
         Total |        59         41 |       100
               |    100.00     100.00 |    100.00
    
    
    . mat li freq
    
    freq[2,2]
        c1  c2
    r1  41  27
    r2  18  14
    
    . bysort yy zz : gen freq = _N
    
    . egen tag = tag(yy zz)
    
    . l yy zz freq if tag
    
         +----------------+
         | yy   zz   freq |
         |----------------|
      1. |  0    0     41 |
     42. |  0    1     27 |
     69. |  1    0     18 |
     87. |  1    1     14 |
         +----------------+
    3. https://www.statalist.org/forums/for...updated-on-ssc

    Comment

    Working...
    X