Announcement

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

  • Data Type Long addition issues

    Dear Forum,

    One of my variables got imported as long data type. The issue that I am experiencing is when I add this variable to other variables which are classified as float I get results which do not make sense.

    For eg. one of the values of the long variable is 10, when I add it to another float variable whose value is 640 , I get the result as 715.

    When I use the display command the long variable, which shows up as 10 shows up as 75.I want the variable to reflect the displayed value which is 10. can you please advise how can I resolve this.

    . display level_change
    75

    Click image for larger version

Name:	long.jpg
Views:	2
Size:	2.4 KB
ID:	1701198

    Attached Files
    Last edited by srikant vinakota; 11 Feb 2023, 05:49.

  • #2
    I doubt this is anything to do with storage or variable type,


    In this case I guess -- in fact your results tell me -- that your variable has numeric value 75 and value label "10", When you add 640 to 75, you will get 715,

    I would be very careful here. There is a mismatch between numeric values and numeric-seeming value labels. Upstream of this may be an encode that was misguided. So look carefully at the results of

    Code:
    tab level_change, missing 
    
    tab level_change, nola missing

    Comment


    • #3
      What you see are value labels, not values of the variable. If you need to use the value labels, decode the variables and destring the decoded variables.

      Code:
      decode level_change, gen(level_change_val)
      destring level_change_val, replace
      Note: Crossed with #2.
      Last edited by Andrew Musau; 11 Feb 2023, 06:57.

      Comment

      Working...
      X