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 11:51:49 -0000

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. 

Nick 
[email protected] 

Suzy
 
> Thanks Austin!
 
Austin Nichols

> >No idea why you would want to do it, but it's easy with -forval-
> >
> >clear
> > set obs `=26*35'
> > g x=.
> > g a=.
> > g i=.
> > local n=1
> >forv i=1/26 {
> >    forv a=1/35 {
> >     qui  replace x=`i'`a' in `n'
> >     qui  replace i=`i'  in `n'
> >     qui  replace a=`a' in `n'
> >   local n=`n'+1
> >  }
> >}

Suzy 

 >>I am entering in some data manually and I would like to be able to
> >>quickly insert unique numeric identifiers which represent 
> 26 individual
> >>subjects each with 35 attributes.
> >>
> >>        The values for the individual identifiers look like this:
> >>
> >> subject 1 with 1-35 attributes =
> >>11,12,13,14,....110,111,112...120,121,122...130,131,132,133,134,135
> >> subject 2 with 1-35 attributes =
> >>21,22,23,24,....210,211,212...220,221,222...230,231,232,233,234,235
> >> subject 3 with 1-35 attributes =
> >>31,32,33,34.....310,311,312...320,321,322...330,331,332,333,334,335
> >>
> >>etc. to subject 26 w/ 1-35 attributes...261,262,263
> >>
> >>These values will be manually inputted in one column under 
> varname (obs)
> >>in ascending order of subject number(s) and attribute number(s).
> >>
> >>obs
> >>11
> >>12
> >>13
> >>14
> >>.etc
> >>.etc
> >>110
> >>111
> >>112
> >>.etc
> >>.etc
> >>.etc
> >>21
> >>22
> >>23
> >>24
> >>25
> >>.etc
> >>.etc
> >>.etc
> >>

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