Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: combining two variables into one with matching type


From   Shawn DuBravac <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: combining two variables into one with matching type
Date   Sun, 8 Dec 2013 13:32:01 -0500

Trying to combine two variables into 1, but getting "type mismatch" despite the fact both variables have the same format

. gen str5 zipcode1 = string(zipcode,"%05.0f")
. destring zip, generate(zip1)
zip has all characters numeric; zip1 generated as long
(32340 missing values generated)

. gen str5 z1 = string(zip1,"%05.0f")

. 
. gen zipfinal= z1

. replace zipfinal=zipcode1 if zipfinal==.
type mismatch
r(109);

end of do-file
r(109);

. do "C:\Users\SDUBRA~1.CE\AppData\Local\Temp\STD01000000.tmp"

. describe zipcode1 z1 zipfinal

              storage  display     value
variable name   type   format      label      variable label
-------------------------------------------------------------------------------
zipcode1        str5   %9s                    
z1              str5   %9s                    
zipfinal        str5   %9s                    

. 
end of do-file 

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index