Announcement

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

  • Displaying thousands with "K" suffix

    I wish that my data will display shortened numbers, for example:

    I wish to display the number "100000" as "100K"

    Is that possible?

    MWE:
    Code:
    di 100000
    Stata/MP 15.1

  • #2

    Code:
    di "100K"
    is a trivial answer. Otherwise, divide a number by 1000, decide what you want to display (decimal parts?) and then display "K".

    If you had a numeric variable then I don't see any way to get that in listings or tables except through converting to string.

    Comment


    • #3
      Originally posted by Nick Cox View Post
      Code:
      di "100K"
      is a trivial answer. Otherwise, divide a number by 1000, decide what you want to display (decimal parts?) and then display "K".

      If you had a numeric variable then I don't see any way to get that in listings or tables except through converting to string.
      Hello Nick I have a related but different question: I need help with converting a particular variable to numbers. The variable in question is the amount of damage done by different disasters. The values were entered as for example 1K (Meaning $1000) and 1M (Meaning $1000000). I will want to convert these values to just numbers. Is there a way to do this in STATA.
      PS: As the variable is continuous there are different observations with the "K" suffix e.g. 9K, 12K etc. Also there are different observations with the "M" Suffix.
      I will really appreciate your insight on this, as I have a very large data set
      I use STATA16

      Comment


      • #4
        A data example would have helped but the following code should do it

        Code:
        *Let the current variable be "damage" and k denotes $1000 and m denotes $1000000
        gen dummy = ustrright(dummy,1)
        split damage, parse(k m)
        destring damage1,replace
        gen damage_n = damage1*1000 if dummy=="k"
        gen damage_n = damage1*1000000 if dummy=="m"
        
        *not the most elegant solution but should work

        Comment

        Working...
        X