Announcement

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

  • Problem with destring: loosing unique values

    Hi everyone, I have a problem when destring a variable into numeric. I have created my observations ID using the egen + concat function:

    egen folionumeric = concat(cd_a ent est est_d con v_sel tipo mes_cal n_hog h_mud n_ren)

    they are all numeric variables. So, what I get is a string that 'looks like' composed of numbers. Fine.
    However, I need to declare my panel, so I need a numeric variable. Then what I did is:

    destring folionumeric, replace
    folionumeric: all characters numeric; replaced as double

    Stata says that they were all numeric so everything looks fine. However, it seems that I have a different number of unique values between the pre-string variable and the destring variable. Do you have any idea of why this happen? here follows a screenshot of the description of the two variables.

    Click image for larger version

Name:	stata.png
Views:	2
Size:	36.0 KB
ID:	1748516


    The code is about 1 million observations, so I do not know how to inspect what happens without checking observation by observation.
    Thank you very much.
    Attached Files

  • #2
    The exercise is doomed. You could hold numbers like 8.632e19 in doubles, but many will be rounded, and you can't hold even all the possible integer values.

    Try this instead


    Code:
    egen long id = group(cd_a ent est est_d con v_sel tipo mes_cal n_hog h_mud n_ren)
    A long will hold the integers you needed.

    Code:
    . gen long test_id = 381355
    
    . replace test_id = test_id + 1
    (1 real change made)

    Comment

    Working...
    X