Hi,
I'm using Stata/SE 12.0 with Windows 10 and I've been blocking for a while on something. The only post I found on the subject was from Paula de Souza but what was suggested there does not seem to work in my case.
I have merged 2 files and what I want is that when the variable gdp_o has missing values, it would be replaced by GDP values but I keep getting the "type mismatch" error. GDP was a string14, I have done destring but then GDP becomes a "double, %10.0g" type while gdp_o is a "float, %9.0g" type. So when I want to replace, I get:
Result # of obs.
-----------------------------------------
not matched 21,638
from master 20,750 (_merge==1)
from using 888 (_merge==2)
matched 587,218 (_merge==3)
-----------------------------------------
. order Countryrep Coderep Codepar year GDP gdp_o gdp_d
. replace GDP ="." if GDP ==".." | GDP =="_"
(18449 real changes made)
. destring GDP, replace ignore(" ")
GDP has all characters numeric; replaced as double
(39200 missing values generated)
.
. format gdp_o %10.0g
. format gdp_d %10.0g
. replace gdp_o =GDP if gdp_o == "."
type mismatch
r(109);
Then I tried
compress GDP
compress GDP
. format gdp_o %10.0g
. recast float GDP
GDP: 565006 values would be changed; not changed
. recast float GDP
GDP: 565006 values would be changed; not changed
. recast double gdp_o gdp_d /// to convert gdp_o in double
. recast double gdp_o gdp_d
. format gdp_o gdp_d %10.0g
> format gdp_o gdp_d %10.0g*/
. recast float GDP, force
GDP: 564053 values changed
. replace gdp_o =GDP if gdp_o == "."
type mismatch
It would be great if someone could tell me why I keep having this mismatch message, even when I see in the variables manager table that the 2 variables are the same type.
Thanks a lot!

I'm using Stata/SE 12.0 with Windows 10 and I've been blocking for a while on something. The only post I found on the subject was from Paula de Souza but what was suggested there does not seem to work in my case.
I have merged 2 files and what I want is that when the variable gdp_o has missing values, it would be replaced by GDP values but I keep getting the "type mismatch" error. GDP was a string14, I have done destring but then GDP becomes a "double, %10.0g" type while gdp_o is a "float, %9.0g" type. So when I want to replace, I get:
Result # of obs.
-----------------------------------------
not matched 21,638
from master 20,750 (_merge==1)
from using 888 (_merge==2)
matched 587,218 (_merge==3)
-----------------------------------------
. order Countryrep Coderep Codepar year GDP gdp_o gdp_d
. replace GDP ="." if GDP ==".." | GDP =="_"
(18449 real changes made)
. destring GDP, replace ignore(" ")
GDP has all characters numeric; replaced as double
(39200 missing values generated)
.
. format gdp_o %10.0g
. format gdp_d %10.0g
. replace gdp_o =GDP if gdp_o == "."
type mismatch
r(109);
Then I tried
compress GDP
compress GDP
. format gdp_o %10.0g
. recast float GDP
GDP: 565006 values would be changed; not changed
. recast float GDP
GDP: 565006 values would be changed; not changed
. recast double gdp_o gdp_d /// to convert gdp_o in double
. recast double gdp_o gdp_d
. format gdp_o gdp_d %10.0g
> format gdp_o gdp_d %10.0g*/
. recast float GDP, force
GDP: 564053 values changed
. replace gdp_o =GDP if gdp_o == "."
type mismatch
It would be great if someone could tell me why I keep having this mismatch message, even when I see in the variables manager table that the 2 variables are the same type.
Thanks a lot!
Comment