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   Maarten buis <[email protected]>
To   [email protected]
Subject   Re: st: incorrect results seen when creating new variable by multiplying existing variables
Date   Wed, 9 Mar 2011 07:52:50 +0000 (GMT)

--- On Wed, 9/3/11, Mariano Matias Iberico 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.

This is a precision problem. There are many sources where you can
read more about it. One that focusses on your type of problem, i.e.
generating a identifier variable is:
<http://www.ats.ucla.edu/stat/Stata/faq/longid.htm>

To take your example, you can fix it as follows:

*-------------- begin example ------------------
 sysuse nlsw88.dta, clear
 keep idcode age grade
 replace grade=1 if grade==.
 generate double newid=.       // <-- only this line was changed
 format %11.0g newid
 replace newid=_n*10000+age*100+grade
 list newid idcode age grade in 2236
*--------------- end example -------------------

Hope this helps,
Maarten

--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany

http://www.maartenbuis.nl
--------------------------


      

*
*   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