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: incorrect results seen when creating new variable by multiplying existing variables


From   Joerg Luedicke <[email protected]>
To   [email protected]
Subject   Re: st: incorrect results seen when creating new variable by multiplying existing variables
Date   Wed, 9 Mar 2011 00:04:06 -0500

On Tue, Mar 8, 2011 at 11:17 PM, Mariano Matias Iberico
<[email protected]> wrote:
> I have a problem when trying to generate a new master variable to identify
> clusters for an -expand– I use later.
> When passing into 1000s of observations the newid variable becomes funky.
> I managed to recreate the problem using a stata dataset:
> .  sysuse nlsw88.dta
> .  keep idcode age grade
> .  replace grade=1 if grade==.
> .  generate newid=.
> .  format %11.0g newid
> .  replace newid=_n*10000+age*100+grade
> The problem is evident if you look at observation 2236 for example.
> Newid    idcode age grade
> 22364108 5127   41  7
> The grade portion of the newid does not parse with the actual grade
> variable.
> When using:
> .  display 2236*10000+41*100+7
> The result is fine!
> This same problem occurs with observations 2238, 2241 and many others.
> I can't figure out why this is occurring!

you should probably generate newid as double such as:

generate double newid=.

hth,

J.

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


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