Announcement

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

  • How to insert a comma in numeric variable

    Dear Statalists,

    I have converted a string variable to a numeric variable but the commas have gone missing. The string variable was for example 51.00, the numeric variable is now 5100, so the comma is missing. The variable represents the ownership of shareholders in percent.

    Do you have any ideas how I can fix my numeric variable and insert a comma?

    Thank you very much in advance for your help and your time!

    Chris

  • #2
    Please show use what you have done, i.e. show us an example of what you started with, what you have typed and what you have ended up with. Do all that using dataex. If this is new to you, take a couple of minutes and quickly review the FAQs (especially section 12).

    Best
    Daniel
    Last edited by daniel klein; 21 Feb 2018, 08:45.

    Comment


    • #3
      you need to read:
      Code:
      help format
      and pay attention to "set dp" in that help file (note that I am making some assumptions here that would have been answered if you had read the FAQ prior to posting)

      Comment


      • #4
        Rich Goldstein daniel klein
        Sorry for my imprecise question!
        My variable was str13 with the display format %13s and now is a long variable with display format %8.0g.

        I tried the following command which didn't help to solve my problem.
        Code:
        format ISH_Total_Perc %8.0gc
        Do you have any suggestions how I can solve this?
        Thank you very much in advance!

        Comment


        • #5
          Still not precise enough. How did you convert your original variable? Please give an example of the hole process, like the one below

          Code:
          clear
          input str13 original
          "51.00"
          end
          
          destring original , generate(numeric)
          
          list
          
          format %9.2fc numeric
          
          list
          gives

          Code:
          . clear
          
          . input str13 original
          
                    original
            1. "51.00"
            2. end
          
          . 
          . destring original , generate(numeric)
          original: all characters numeric; numeric generated as byte
          
          . 
          . list
          
               +--------------------+
               | original   numeric |
               |--------------------|
            1. |    51.00        51 |
               +--------------------+
          
          . 
          . format %9.2fc numeric
          
          . 
          . list
          
               +--------------------+
               | original   numeric |
               |--------------------|
            1. |    51.00     51.00 |
               +--------------------+
          
          . 
          end of do-file
          Best
          Daniel

          Comment

          Working...
          X