Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: creating unique identifier values


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: creating unique identifier values
Date   Thu, 9 Mar 2006 13:36:56 -0000

This can also easily be modified to meet 
Richard's comment. For example, 

gen x = string(x1) + "_" + string(x2)) 

is such that "2_11" can be distinguished 
from "21_1". 

Nick 
[email protected] 

Nick Cox
 
> Noting Richard Williams' caveat, and just
> focusing on the question, it can also be 
> done without loops: 
> 
> set obs `=26 * 35' 
> egen x2= seq(), to(35) 
> egen x1= seq(), block(35) 
> gen x = real(string(x1) + string(x2)) 
> 
> -egen- haters can do it without any interpreted
> code: 
> 
> set obs `=26 * 35' 
> gen x1 = ceil(_n/35) 
> gen x2  = 1 + mod(_n-1, 35) 
> gen x = real(string(x1) + string(x2)) 
> 
> and that could be telescoped further. 
> 

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index