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]

Re: st: combining two variables into one with matching type


From   Nick Cox <njcoxstata@gmail.com>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: combining two variables into one with matching type
Date   Sun, 8 Dec 2013 18:38:51 +0000

They have the same format, but that's not the issue.

As -zipfinal- is string, its values can never be equal to system
missing . which is a numeric value.

If you want to refer to missing values of -zipfinal-, they have value
"" or return 1 (true) to -missing(zipfinal)-.

(Your code doesn't give a clear idea of what you want to do, but I
focused on your question.)

Nick
njcoxstata@gmail.com


On 8 December 2013 18:32, Shawn DuBravac <sdubravac@ce.org> wrote:

> 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