Announcement

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

  • New table and collect command: Add rows with bold text to table

    I am building a simple summary table of multiple categorical variables with the new commands table and collect. I would like to add rows with bold text to my table to differentiate between my IVs, DVs and Moderators. In the example below, I would like to add one row above my variable "Industry" and one row above my variable "Occupation". Above "Industry" I would like to add bold text "DV", above "occupation" I would like to add "IV". It could be in the same column (indented or not), or in new column left to the variable column.
    Code:
    use https://www.stata-press.com/data/r17/nlsw88.dta
    table, stat(fvfrequency industry) statistic(fvpercent industry) stat(fvfrequency occupation) statistic(fvpercent occupation)
    collect layout (var) (result)
    collect label levels result fvfrequency "Freq." fvpercent "Percent", modify
    collect style row stack, nobinder
    collect export sample.description2.docx, as(docx) replace
    __________________________________________________ __________

    Cheers, Felix
    Stata Version: MP 18.0
    OS: Windows 11

  • #2
    Code:
    collect clear
    sysuse nlsw88, clear
    table, stat(fvfrequency industry) statistic(fvpercent industry) stat(fvfrequency occupation) statistic(fvpercent occupation)
    collect layout (var) (result)
    collect label levels result fvfrequency "Freq." fvpercent "Percent", modify
    collect style row stack, nobinder
    collect addtags vartype[DV], fortags(industry)
    collect addtags vartype[IV], fortags(occupation)
    collect style header vartype, title(hide)
    collect style cell vartype#cell_type[row-header], font(,bold)
    collect style cell var[occupation]#cell_type[row-header], font(,nobold)
    collect style cell var[industry]#cell_type[row-header], font(,nobold)
    collect layout (vartype#var) (result)
    which produces:
    Click image for larger version

Name:	Screenshot 2022-11-02 at 2.50.14 AM.png
Views:	1
Size:	139.1 KB
ID:	1687654

    Comment


    • #3
      Thank you Hemanshu Kumar!
      __________________________________________________ __________

      Cheers, Felix
      Stata Version: MP 18.0
      OS: Windows 11

      Comment


      • #4
        Hi there, I am trying to create two tables and append them as Panel A and B. My current command is as follows but this only shows the second option. How can I export a table of percentages to an excel/latex file using the collect option? My code is similar to the following.

        collect clear

        table race gender, stat(percent)

        table race gender, statistic(percent, across(gender)) append

        collect export table1.xlsx, replace

        Desired outcome would look something like the below table

        Click image for larger version

Name:	Screenshot 2023-03-31 at 11.57.41 AM.png
Views:	2
Size:	79.8 KB
ID:	1707975



        Comment


        • #5
          Hello @Hemanshu Kumar
          I have tried your suggestion repeatedly and I can't seem to get it to work. Would you be willing to take a look at my code?


          Code:
           table (var) (placement) [ pweight = xh81 ], totals(placement) statistic(freq) 
          table (h6) (placement) () [ pweight = xh81 ], totals(placement) statistic(freq) statistic(percent placement, across(h6)) zerocounts nformat(%9.1f percent) sformat(`"%s%%"' percent)  append
          putdocx clear
          putdocx begin
          collect addtags vartype[DV], fortags(h6)
          collect style cell vartype#cell_type[row-header], font( ,bold)
          collect style cell var[h6]#cell_type[row-header], font( ,nobold)
          collect style row stack, spacer
          collect style header var, level(hide)
          collect style header result, level(hide)
          collect style putdocx, layout(autofitcontents) halign(center)
          collect layout (vartype#var) (result)
          collect title "Respondents Report of Other Parent's Relationship w/ Child"
          collect note "Reported percentages are weighted and totals are raw."
          putdocx collect 
          putdocx save "${data_box}Section_H\FullSample\OP_relationship", replace
          Last edited by Quinn Kinzer; 07 Aug 2024, 11:29.

          Comment

          Working...
          X