Announcement

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

  • How to format the percentge to 2 decimal places

    Hi Family,
    I have three(3) variables that I have run crosstabulation and append them in one table, using the coded below;
    But after running the table, I realized the percentage is in 5 decimal places but I rather need the final percentage in to 2decimal places rather.

    table (agegp) (dep_var), statistic(percent, across(dep_var)) nototals
    table (mstatus) (dep_var), statistic(percent, across(dep_var)) nototals append
    table (ternue) (dep_var), statistic(percent, across(dep_var)) nototals append
    collect layout (agegp mstatus ternue) (dep_var)


    Any help?

    . dataex dep_var agegp ternue mstatus

    ----------------------- copy starting from the next line -----------------------
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float dep_var int agegp byte(ternue mstatus)
    1 1 3 3
    1 2 3 1
    1 2 3 1
    0 2 3 1
    1 2 3 1
    1 1 3 3
    1 4 3 2
    1 2 3 1
    1 1 3 3
    1 1 3 3
    1 4 3 2
    1 2 3 1
    1 1 3 3
    1 1 3 1
    1 1 3 1
    1 1 1 1
    1 4 3 2
    1 1 3 1
    1 2 3 1
    0 2 3 1
    end
    label values dep_var dep_var
    label def dep_var 0 "mild anxiety", modify
    label def dep_var 1 "severe anxiety", modify
    label values agegp agegp
    label def agegp 1 "18-30", modify
    label def agegp 2 "31-45", modify
    label def agegp 4 "61+", modify
    label values ternue ternue
    label def ternue 1 "Rent (Private, Social housing)", modify
    label def ternue 3 "Other (living family and friends, holiday)", modify
    label values mstatus mstatus
    label def mstatus 1 "In union (living with partner and married)", modify
    label def mstatus 2 "Formerly in union (divorced, widowed)", modify
    label def mstatus 3 "Never Married (Single)", modify

    Thank you.
    Last edited by Shamsudini Amidu; 24 Nov 2023, 03:15.

  • #2
    That is what the nformat() option is for. For example: table (agegp) (dep_var), statistic(percent, across(dep_var)) nototals nformat(%9.2f)
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Hi Marten,
      Thank you very much it is working.
      I also need to add chi-square and p-value as part of the crosstabulation to the command is it possible to add it to the command?
      table (agegp) (dep_var), statistic(percent sig chi, across(dep_var)) nototals nformat(%9.2f)

      I appreciate your support.

      Thank you Sir.
      Amidu

      Comment

      Working...
      X