Announcement

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

  • expand 2x2 table by merging additional variables as columns with tabout or putexcel

    Hi,

    I have a data that looks like this:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long ID byte(Region Type Tier Secure Offshore Highland)
    120034 12 1 2 1 0 1
    120035 12 1 2 1 0 1
    120036 12 1 2 1 0 1
    120037 12 1 2 1 0 1
    120038 41 1 2 1 0 0
    120039 41 2 2 1 1 0
    120040 41 2 1 0 1 0
    120041 41 2 1 0 1 0
    120042 41 2 1 0 1 0
    120043 41 2 1 0 0 .
    120044 65 2 1 0 0 .
    120045 65 3 1 0 0 0
    120046 65 3 1 1 0 0
    120047 65 3 2 1 1 0
    120048 65 3 2 1 0 0
    120049 65 3 2 . 1 1
    120050 25 3 2 . 1 1
    120051 25 5 2 . 1 1
    120052 25 5 1 . 0 1
    120053 25 5 2 . 0 .
    120054 25 5 2 0 0 .
    120055 25 5 1 0 . 0
    120056 25 5 1 0 . 0
    120057 95 7 1 0 1 0
    120058 95 7 1 0 1 0
    120059 95 7 1 1 1 0
    120060 95 7 2 1 0 1
    120061 95 7 2 1 0 1
    120062 59 7 2 1 0 1
    120063 95 8 2 0 . 1
    120064 59 8 1 0 . 1
    120065 59 8 1 0 . 0
    120066 59 8 1 1 . 0
    120067 59 8 1 1 1 0
    120068 59 8 2 1 1 0
    120069 40 9 2 1 1 1
    120070 40 9 2 1 0 1
    120071 40 9 2 1 0 1
    120072 40 9 1 0 0 1
    end
    But only lots of more binary outcome variables.
    I am creating table with the following code:

    Code:
    foreach v of var Secure Offshore Highland{
        tabout Region Type Tier `v' using `v'.docx ///
        , replace ///
        style(docx) font(bold) c(freq row) ///
        f(1) layout(cb) landscape nlab(Obs) paper(A4)
        }
    It has both row freq and % and final right column of row total (obs). But i needed only % of "1" and rowtotal. So i wrote the following:

    Code:
    foreach v of var Secure Offshore Highland{
        tabout Region Type Tier `v' using `v'.docx ///
        , replace ///
        style(docx) font(bold) c(freq row) ///
        f(1) layout(cb) h3(nil) h2(nil) dropc(2 3 4 5 7) landscape nlab(Obs) paper(A4)
        }
    where, upper two unimportant heading row is deleted and column 2,3,4,5,7 is deleted. Now this is what i needed !
    But, both the codes create three individual tables for each outcome variables. I have to manually make one table combining the three tables keeping the left-most column, the % of "1" column and the right-most column showing the row-total (Obs).

    Can anyone help me out here regarding:
    1. Merging all the tables in one go, keeping the exploratory variable labels on the left-most and the rowtotal (obs) on the right-most column
    2. Instead of deleting the columns except % of "1"s, i want only to have the desired column. Deleting columns seem so crude and dangerous.
    3. Can i get this same output in excel through "putexcel"? I tried following the wonderfully written blog by Chuck Huber. But can't figure out the "merging" part

    I came this far due to lots and lots of studying, Especially Ian Watson's "User Guide for tabout Version 3" and Nicholas Cox's "How to face lists with fortitude".

    Thanks in advance
    Mahmood

  • Mahmoodur Rahman
    replied
    I got great response in the cross-posted link. But still struggling a bit for more efficient loops to merge columns and yet keep fixed left-hand column of category-definitions and constant right-hand-side row-totals columns.

    Leave a comment:


  • Nick Cox
    replied
    Cross-posted at https://stackoverflow.com/questions/...about-or-putex Please remember to tell us about cross-posting.

    Leave a comment:

Working...
X