Hi,
I am facing problems with replacing variables.
I have three variables.
Since "dist" is a byte variable, I converted it to a string variable:
Now,
I want to replace the values in "dist" with those from "d1" and "d2":
However, the type mismatch problem still exists:
I’ve provided a small dataset for your reference.
Appreciate your help.
I am facing problems with replacing variables.
I have three variables.
Code:
. des dist d1 d2
Variable Storage Display Value
name type format label Variable label
--------------------------------------------------------------------------------------------------
dist byte %10.0g dist
d1 str9 %9s d1
d2 str16 %16s d2
Since "dist" is a byte variable, I converted it to a string variable:
Code:
. tostring dist, replace dist was byte now str1
Now,
Code:
. des dist d1 d2
Variable Storage Display Value
name type format label Variable label
--------------------------------------------------------------------------------------------------
dist str1 %9s dist
d1 str9 %9s d1
d2 str16 %16s d2
I want to replace the values in "dist" with those from "d1" and "d2":
Code:
replace dist = d1 if dist == .
However, the type mismatch problem still exists:
Code:
. replace dist = d3 if dist == . type mismatch r(109);
I’ve provided a small dataset for your reference.
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str1 dist str9 d1 str16 d2 "." "" "" "." "" "" "." "" "" "." "" "" "." "" "" "." "" "" "." "" "" "." "" "" "." "" "" "." "" "" "." "" "" "." "" "" "." "" "" "." "" "" "." "" "Lahaul and Spiti" "." "" "" "." "" "Lahaul and Spiti" "." "" "Hamirpur" "." "" "" "." "" "" end
Appreciate your help.

Comment