Announcement

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

  • change variables with nummeric of length n to nummeric with single digit before comma andrest after it.

    Dear Statalist users,

    I have got a variable which contains different nummeric values of different lengths which I want to change into a nummeric variable that has 1 digit before the comma and the rest after the comma

    For example: var [1111; 2222; 333; 44; 5; 6666666]
    I'd like to change this variable to [1.111; 2.222; 3.33; 4.4; 5; 6.666666]

    Does anyone know how I can accomplish this?

    Thanks in advance,

    Emilio



  • #2
    Here's one solution that works with your example data:
    Code:
    clear
    input x
    1111
    2222
    333
    44
    5
    6666666
    end
    //
    gen str temp = strofreal(x)
    gen newx = real(substr(temp,1,1) + "." + substr(temp,2,.))
    list

    Comment


    • #3
      Here is another

      Code:
      clear
      input foo
      1111
      2222
      333
      44
      5
      6666666
      end
      
      generate bar = foo/10^(strlen(strofreal(foo))-1)
      list
      This seems like a strange problem to solve.

      Best
      Daniel

      Comment


      • #4
        Works like a charm, thanks a lot Mike!

        Comment


        • #5
          Also thanks to you Daniel!

          Comment

          Working...
          X