Announcement

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

  • How can I make dtable display row percentages?

    Hi Statalist
    I have a dataset with few categorical variables. I am trying to use dtable to make a table of participant characteristics by a dichotomous outcome "comp_know".
    I am using the following code:
    Code:
    dtable i.agegrp i.marstat i.educ i.income i.incomesource, by(comp_know, tests) column(test("p-value")) title("Outcome by Participant Characteristics") sample( , statistics(frequency) place(inlabels)) sformat("(n = %s)" frequency)
    The result I get is this:
    Click image for larger version

Name:	ForStataList.png
Views:	2
Size:	75.8 KB
ID:	1770060


    Here is the dataset :

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input int ptid byte agegrp long(marstat educ incomesource income) float comp_know
    431 4 3 6 3 3 1
    430 3 3 4 2 3 1
    429 1 2 7 1 3 0
    428 2 3 5 2 2 1
    427 1 2 7 1 4 1
    426 1 3 6 4 3 1
    425 2 2 3 1 5 1
    424 1 3 5 2 2 1
    422 2 3 2 1 5 1
    421 1 3 7 1 3 1
    420 2 2 4 1 4 1
    419 1 3 6 1 4 0
    418 1 3 1 5 3 1
    416 4 2 7 3 3 1
    413 2 3 4 7 5 1
    411 1 3 4 1 5 1
    410 1 3 5 3 3 0
    409 4 3 4 3 4 1
    408 1 3 3 2 1 1
    407 1 3 7 1 3 0
    406 1 3 5 6 3 1
    405 3 3 5 3 3 1
    402 2 3 4 6 3 0
    401 2 3 5 1 3 1
    399 1 3 4 2 1 1
    398 2 3 1 5 3 1
    396 2 3 6 2 2 0
    395 3 3 2 1 3 1
    393 1 3 4 2 2 1
    392 1 3 5 1 3 1
    391 1 3 6 2 3 1
    390 4 2 5 1 3 1
    389 2 3 5 5 3 1
    388 4 2 3 1 5 0
    387 1 3 5 5 3 1
    385 2 3 4 1 3 1
    384 1 3 4 2 1 1
    383 2 2 5 4 3 0
    382 1 3 3 2 1 1
    380 3 3 6 1 3 0
    379 2 3 3 5 5 1
    378 2 3 4 5 3 1
    377 3 2 4 3 3 1
    376 1 3 5 4 3 1
    375 2 3 4 3 3 1
    374 2 3 5 1 3 1
    373 2 2 5 1 4 1
    371 1 3 5 1 5 0
    370 2 2 5 2 1 1
    369 4 3 6 3 3 1
    368 2 3 1 2 1 1
    367 2 2 5 1 3 0
    366 4 3 8 1 3 1
    363 2 2 5 1 4 0
    362 2 3 5 1 5 0
    361 1 2 6 5 3 0
    360 1 1 6 1 3 0
    359 2 2 5 1 3 0
    358 1 3 4 2 1 1
    356 3 2 6 1 3 0
    355 3 3 6 5 3 1
    353 2 2 3 1 3 1
    352 2 2 4 1 3 0
    351 1 3 5 2 1 1
    350 1 3 7 1 4 0
    349 2 3 7 5 3 1
    348 1 3 4 2 1 1
    346 1 3 3 2 1 1
    344 3 2 6 3 3 1
    343 4 2 4 1 3 1
    342 1 3 4 2 1 1
    341 2 2 4 1 2 1
    340 1 3 5 6 5 0
    339 3 2 4 6 5 0
    337 1 3 3 2 1 1
    336 2 2 6 6 2 0
    335 1 3 4 5 3 1
    334 3 2 4 1 5 1
    333 4 2 7 4 3 1
    332 3 2 4 2 1 1
    331 2 2 6 4 3 1
    327 1 3 4 2 1 1
    325 4 2 4 6 5 1
    324 4 2 3 1 5 1
    323 2 3 5 4 3 1
    322 1 3 5 6 3 1
    319 3 2 4 4 3 1
    318 1 3 4 2 1 1
    317 1 2 5 1 5 1
    316 3 2 5 4 3 1
    314 1 2 6 1 3 1
    313 1 2 7 4 3 0
    311 2 2 5 3 3 1
    310 4 2 2 1 3 1
    309 4 2 5 1 3 1
    308 2 2 5 1 3 1
    307 2 2 3 5 5 0
    306 2 3 3 2 1 1
    305 1 3 4 6 5 1
    304 2 3 3 5 3 1
    end
    label values agegrp agegrp
    label def agegrp 1 "18-24 years", modify
    label def agegrp 2 "25-29 years", modify
    label def agegrp 3 "30-34 years", modify
    label def agegrp 4 ">=35 years", modify
    label values marstat marstat_n
    label def marstat_n 1 "Divorced", modify
    label def marstat_n 2 "Married", modify
    label def marstat_n 3 "Unmarried", modify
    label values educ educ_n2
    label def educ_n2 1 "Professional course/training", modify
    label def educ_n2 2 "Post-graduate", modify
    label def educ_n2 3 "Graduate", modify
    label def educ_n2 4 "Passed 12th class", modify
    label def educ_n2 5 "Passed 10th class", modify
    label def educ_n2 6 "Passed 8th class", modify
    label def educ_n2 7 "Passed 5th class", modify
    label def educ_n2 8 "Illiterate", modify
    label values incomesource incomesource_n
    label def incomesource_n 1 "Self employed", modify
    label def incomesource_n 2 "Dependent on parents", modify
    label def incomesource_n 3 "Driver", modify
    label def incomesource_n 4 "Labourer", modify
    label def incomesource_n 5 "Salaried", modify
    label def incomesource_n 6 "Street vendor", modify
    label def incomesource_n 7 "Others", modify
    label values income income_n2
    label def income_n2 1 "No income of my own", modify
    label def income_n2 2 "<=5000", modify
    label def income_n2 3 "5001-15000", modify
    label def income_n2 4 "15001-25000", modify
    label def income_n2 5 ">25000", modify
    label values comp_know yn
    label def yn 0 "No", modify
    label def yn 1 "Yes", modify



    My concern is, The dtable displays column percentages. What changes do I need to make in the dtable code so that it displays Row Percenatges. I am using Stata 18.

    Thank You.
    Attached Files

  • #2
    Here is the same question and answers from Stata stuff: https://www.statalist.org/forums/for...row-percentage
    If I understand correctly, the dtable command cannot produce row percentages automatically.

    Comment

    Working...
    X