Announcement

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

  • How to assign a random value for missing months of birth?

    Dear all,

    My data has about 700 observations with missing months of birth and I am trying to fill in those missing values. I am thinking of two options, among others. The first option is to choose 30 June or 1 July for the missing values because those dates are the middle of year. The second one is to assign a random number from 1-12 to the missing values. Any suggestion on how to do the 2nd option in Stata is highly appreciated. Thank you.

    Data
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input double id byte mob int yob
    42063 .    .
    38067 . 1982
    46079 . 1973
    38024 . 1984
    31047 . 1977
    33118 . 1981
    42059 . 1977
    42027 . 1975
    38010 . 1984
    37061 . 1965
    38017 . 1979
    46038 . 1970
    12003 . 1981
    33046 . 1988
     8098 . 1983
    37092 . 1974
    33071 . 1986
    42038 . 1988
    31033 . 1967
    42067 . 1975
    end

  • #2
    Code:
    replace mob = runiformint(1, 12) if missing(mob)
    Also, to make this reproducible, before running this code you should set the random number generator seed if you have not already done so. -set seed pick_a_number_any_integer_will_do-. That way if you re-run this code in the future, you will get the same results.
    Last edited by Clyde Schechter; 23 Dec 2021, 10:27.

    Comment


    • #3
      Thank you Prof. Clyde for the code as well as suggestion on the use of setting seed.

      Comment

      Working...
      X