Announcement

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

  • removing decimals

    I want to remove the decimal places from age but without rounding.

    e.g. 75.6 to 75 (and not 76)


    . dataex age_new

    ----------------------- copy starting from the next line -----------------------
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float age_new
     12.93087
     17.64271
     54.23682
     43.75633
     62.94045
     66.98426
     68.85695
     40.30664
     43.37303
     42.43395
     42.68036
    36.689938
    34.710472
     40.71458
     42.75428
     40.86242
     56.03833
     58.06434
     50.76523
      54.8063
     42.82546
     49.70842
     54.10541
      54.5681
     51.21424
     72.73374
     45.02943
     47.06366
     65.17454
     66.20397
     57.22929
     67.35387
     68.36961
     44.79398
     42.79808
     58.98426
     59.99179
     61.05133
    72.057495
     63.08008
     62.08624
     60.10678
     64.11499
     53.11704
     69.11704
     67.12115
     57.12799
     49.13073
     43.16222
     51.16769
     55.17043
    74.225876
     57.46475
      50.4668
     42.46954
     61.60164
     41.70842
     41.89185
     76.91171
     68.91718
     69.97947
     84.98837
     84.98837
     79.98905
     79.98905
     79.98905
     79.98905
     79.98905
     83.98905
     79.98905
     79.98905
     79.98905
     79.98905
     79.98905
     79.98905
     87.98905
     79.98905
     74.98973
     78.98973
     82.98973
     74.98973
     74.98973
     82.98973
     74.98973
     78.98973
     78.98973
     82.98973
     82.98973
     74.98973
     74.98973
     78.98973
     78.98973
     74.98973
     74.98973
     78.98973
     74.98973
     74.98973
     74.98973
     74.98973
     78.98973
    end

  • #2
    Hi Sonia, I would recommend the floor() function when generating your new variable:

    Code:
    gen age_int = floor(age_new)

    Comment


    • #3
      Another option is to use -int()- which returns on the integer component.

      Comment

      Working...
      X