Announcement

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

  • Formatting to two decimal places

    Hello,

    For some reason I'm having this weird issue where I format the entries in my data to two decimal places and then try to display the entry to find that the command displays a number to 3 decimal places, even though when I browse the data the numbers are all to two decimal places.

    Code:
    . format _all %9.2f 
    
    . display %9.2f scount sample==1
         0.681
    The actual entry is 0.68, when I write 'display %9.1f scount sample==1' it displays 0.71 which is also weird.

    Please can you let me know how I can get the command to display exactly what's in the entry in the browse data section.

    Thanks,
    Jad

  • #2
    When you display a variable, what you get is the first observation of that variable. In this case, you are asking to simultaneously display one variable "scount" and to evaluate whether "sample[1]==1" is true (1 if true, 0 if false). The values are concatenated, and therefore you get

    Code:
    %9.2f scount[1]=0.68
    and
    Code:
    sample[1]==1 = 1 (or true)
    and thus 0.681. The display format will only apply to the first variable. Instead, I think you want:

    Code:
    format _all %9.2f
    list scount if sample==1
    You can use -if- or -in- to constrain the observations to be displayed.

    see

    Code:
    help list
    Last edited by Andrew Musau; 16 Dec 2023, 16:25.

    Comment

    Working...
    X