Announcement

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

  • table with two distinctive informations per cell

    Hello!
    I'm new to STATA and would like to recreate this table. But I can't integrate the second element between brackets.
    Does anyone know how to put these two informations side by side in each cell?
    Rural Communities Landowners Chambers of Commerce Urban Curia Sum
    Lower Austria 5 (4) 5 (3) 7 (7) 17 (14)
    Upper Austria 4 (3) 2 (1) 1 (1) 3 (3) 10 (8)
    Salzburg 1 (0) 1 (1) 1 (1) 3 (2)
    Styria 5 (2) 3 (3) 1 (1) 4 (4) 13 (10)
    Sum 15 (9) 11 (8) 3 (3) 14 (14) 43 (34)
    (Each cell contains the number of representatives in our dataset for a given province and curia and the number of representatives voting in favor of the reform (in brackets).)

    Tank you for your help )

  • #2

    This can be done with the table command starting with Stata 17.

    Absent an example dataset, I simulated something (hopefully) similar to
    your data based on the example table you present.

    In the following I use table to build a table with your summary
    statistics, then use collect commands to change some styles and
    labeling to get the table looking closer to your example.
    Code:
    * simulate example data
    set seed 17
    set obs 43
    gen id = _n
    gen province = runiformint(1,4)
    label define provlab ///
        1 "Lower Austria" ///
        2 "Upper Austria" ///
        3 "Salzburg" ///
        4 "Styria"
    label values province provlab
    gen curia = runiformint(1,4)
    label define curlab ///
        1 "Rural Communities" ///
        2 "Landowners" ///
        3 "Chamber of Commerce" ///
        4 "Urban Curia"
    label values curia curlab
    gen favor = runiformint(0,1)
    
    * build the table
    table (province) (curia) , ///
        statistic(frequency) ///
        statistic(total favor)
    
    * remove unwanted header information
    collect style header, title(hide)
    collect style header result, level(hide)
    
    * put parens around the favor tally
    collect style cell result[total], sformat("(%s)")
    
    * put cell frequency and favor tally together in the cell
    collect composite define stats = frequency total, trim
    collect style autolevels result stats, clear
    
    * change the "Total" labels to "Sum"
    collect label list province
    collect label levels province .m "Sum", modify
    collect label list curia
    collect label levels curia .m "Sum", modify
    
    collect preview
    Here is the resulting table
    Code:
    . collect preview
    
    ---------------------------------------------------------------------------------------------
                  |  Rural Communities   Landowners   Chamber of Commerce   Urban Curia       Sum
    --------------+------------------------------------------------------------------------------
    Lower Austria |              1 (0)        3 (2)                 2 (0)                   6 (2)
    Upper Austria |              2 (0)        5 (3)                 2 (1)         8 (4)    17 (8)
    Salzburg      |              2 (1)        5 (2)                 3 (3)         3 (0)    13 (6)
    Styria        |              1 (1)        2 (1)                 2 (0)         2 (1)     7 (3)
    Sum           |              6 (2)       15 (8)                 9 (4)        13 (5)   43 (19)
    ---------------------------------------------------------------------------------------------

    Comment


    • #3
      Thank you for your help!!! It's almost working ^^, but for the command "collect composite" I receive the message "collect composite not recognized" and i didn't manage to figure out why and how to correct it...
      Do you have an idea what it means and what i can do to make it work?

      Comment


      • #4
        In your Stata 17 session type
        Code:
        update all
        Last edited by Jeff Pitblado (StataCorp); 31 Aug 2023, 13:03.

        Comment


        • #5
          Now it's all working! once again thank you

          Comment

          Working...
          X