Announcement

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

  • How can i know the exact value for a number in STATA and replace

    Dear All

    I have a data set where I want to create a new variable using an existing variable with values as in the data example give below. But when I run the following command it does not replace the value.

    gen N= 0
    replace N = 1.7 if index_B1 ==1.6666666
    and even when I do br if index_B1 ==1.6666666 it does not display anything. Can you please advise as to how to a replace. Similarly for index_B1 ==6.666667 and index_B1 ==3.333333

    clear
    input float index_B1
    1.6666666
    1.6666666
    0
    3.333333
    1.6666666
    5
    1.6666666
    11.666667
    3.333333
    1.6666666
    1.6666666
    0
    1.6666666
    1.6666666
    0
    1.6666666
    8.333333
    1.6666666
    1.6666666
    1.6666666
    1.6666666
    0
    6.666667
    1.6666666
    3.333333
    1.6666666
    1.6666666
    1.6666666
    0
    1.6666666
    3.333333
    8.333333
    0
    1.6666666
    6.666667
    1.6666666
    1.6666666
    1.6666666
    1.6666666
    1.6666666
    0
    1.6666666
    1.6666666
    10
    1.6666666
    6.666667
    1.6666666
    1.6666666
    1.6666666
    3.333333
    6.666667
    0
    1.6666666
    0
    1.6666666
    3.333333
    1.6666666
    1.6666666
    1.6666666
    8.333333
    1.6666666
    1.6666666
    1.6666666
    6.666667
    8.333333
    1.6666666
    8.333333
    1.6666666
    1.6666666
    1.6666666
    8.333333
    8.333333
    6.666667
    1.6666666
    8.333333
    1.6666666
    1.6666666
    1.6666666
    3.333333
    1.6666666
    1.6666666
    1.6666666
    1.6666666
    1.6666666
    3.333333
    1.6666666
    3.333333
    5
    1.6666666
    1.6666666
    1.6666666
    1.6666666
    6.666667
    1.6666666
    1.6666666
    1.6666666
    0
    1.6666666
    1.6666666
    1.6666666
    end
    [/CODE]

  • #2
    Read this blog post: https://blog.stata.com/2012/04/02/th...-to-precision/

    Comment


    • #3
      See also https://www.statalist.org/forums/help#spelling

      The question in return is what exactly is your goal. If it is to see only I decimal place, then just write

      Code:
      format %2.1f index_B1
      If it is to round to 1 decimal place then

      Code:
      replace index_B1 = round(index_B1, 0.1)
      is a rough solution, but the format statement is still needed, for the reasons explained at length in Sergei's link.

      Comment

      Working...
      X