asdocx: Export from Stata to Word, Excel, LaTeX & HTML Forums asdocx Forum How to report row percentage and confidence interval using table1 template

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • Ricardo Rodrigues Pereira
    Participant
    Post count: 4

    is there a way to report rows percentage and confidence interval using table1 template? I want my table to look like this example.

             Has used sleeping pills in the last month
    ________________________________________________________________________
                       Yes                            No
    ________________________________________________________________________
     ________%_______95% CI_____________________________%_______95% CI______
    Female 77.64 [75.22, 79.89]  ____________         22.36 [20.11, 24.78] 
    Male   89.67 [88.15, 91.03]  ____________          10.33 [8.97, 11.85]
    _______________________________________________________________________
    
    Attaullah Shah
    Moderator
    Post count: 76

    I have not personally used table1 in my research. Can you advise me if it is appropriate to report confidence intervals for categorical variables?

    Ricardo Rodrigues Pereira
    Participant
    Post count: 4

    Yes, you can report the confidence interval for the proportion. I can get it when I use the command:

    svy:tab variable1 variable2, ci percent

    but it it doesn’t show up when use asdocx, I guess it’s not supported.

    It would look like this: https://media.discordapp.net/attachments/1068130821283786793/1068130857040228433/image.png?width=806&height=473

    Attaullah Shah
    Moderator
    Post count: 76




    I have added the requested feature. First update asdocx with

    asdocx_update

    . Here is an example.

    * Create a toy example
    *generate random number of observations
    clear 
    set obs 200
    
    * create variable for using sleeping pills
    gen use_pills = round(runiform(0,1))
    label define use_pills 0 "Yes" 1 "No"
    label val use_pills use_pills
    label var use_pills "Used sleeping pills in the last month"
    
     *create variable for male and female
    gen gender = round(runiform(0,1))
    label define gender 0 "Female" 1 "Male"
    label val gender gender
    replace use_pills = 1 if gender == 1 & use_pills == 0 & runiform()<0.7
    replace use_pills = 0 if gender == 0 & use_pills == 1 & runiform()<0.3
    

    Row percentage with confidence intervals


    * if row percentages are required

    asdocx tab use_pills gender, template(table1) row cat(% ci) replace 
    Table 1: Demographics
    Variables Yes (n=79) No (n=121) Total (200) P-value
    gender 0.000
    Female
    64.444% (53.921 - 73.735) 35.556% (26.265 - 46.079) 100.000%
    Male
    19.091% (12.731 - 27.622) 80.909% (72.378 - 87.269) 100.000%
    P-values by t-test for continuous variables and Chi2 test for binary/categorical variables.
    * If the total column is not required, use option nototal
    * Add option table_layout(auto) for auto adjust columns for contents
    asdocx tab use_pills gender, template(table1) row cat(% ci) /// 
    replace nototal table_layout(auto)
    Table 1: Demographics
    Variables Yes (n=79) No (n=121) P-value
    gender 0.000
    Female
    64.444% (53.921 - 73.735) 35.556% (26.265 - 46.079)
    Male
    19.091% (12.731 - 27.622) 80.909% (72.378 - 87.269)
    P-values by t-test for continuous variables and Chi2 test for binary/categorical variables.

    Column percentages

    * If col percentages 
    asdocx tab use_pills gender, template(table1) col categorical(% ci) replace 
    Table 1: Demographics
    Variables Yes (n=79) No (n=121) Total (200) P-value
    gender 0.000
    Female
    73.418% (62.455 - 82.097) 26.446% (19.294 - 35.097) 45.0% (38.203 - 51.989)
    Male
    26.582% (17.903 - 37.545) 73.554% (64.903 - 80.706) 55.0% (48.011 - 61.797)
    P-values by t-test for continuous variables and Chi2 test for binary/categorical variables.

    Ricardo Rodrigues Pereira
    Participant
    Post count: 4

    Thank you, Professor. This new feature will be extremely beneficial for not only myself but also a significant number of users. It will greatly aid in my research.

    Ricardo Rodrigues Pereira
    Participant
    Post count: 4

    One more thing, can you look if this can work with the svy command. It doesn’t seem to work for me.

    Attaullah Shah
    Moderator
    Post count: 76

    Support for confidence intervals with survey data has been added. Try this example after updating.

    asdocx_update 
    
    * Results from the Stata command  
    svy: tabulate  diabetes race  , row  ci 
    
    ----------------------------------------------------------------------
    Diabetes  |                            Race                           
    status    |         White          Black          Other          Total
    ----------+-----------------------------------------------------------
     Not diab |         .8812          .0931          .0257              1
              | [.8437,.9107]   [.0705,.122]  [.0111,.0586]               
              | 
     Diabetic |         .8203          .1647          .0151              1
              | [.7476,.8755]  [.1203,.2213]  [.0033,.0668]               
              | 
        Total |         .8791          .0955          .0253              1
              | [.8407,.9093]  [.0725,.1249]  [.0108,.0585]               
    ----------------------------------------------------------------------
    
    * In asdocx, we need to write the treatment variable first 
    asdocx svy: tabulate race diabetes, row  ci  template(table1) replace cat(% ci)  
    Table 1: Demographics
    Variables White (n=9065) Black (n=1086) Other (n=200) P-value
    Diabetes status 0.000
    Not diabetic
    88.121% (84.370 – 91.068) 9.308% (7.045 – 12.201) 2.571% (1.106 – 5.862)
    Diabetic
    82.028% (74.756 – 87.553) 16.467% (12.027 – 22.134) 1.505% (0.325 – 6.680)
    P-values by t-test for continuous variables and Chi2 test for binary/categorical variables. * Design-based Pearson Chi2 test p-value
Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.