| |
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: creating unique identifier values
Thank you all for the coding information! I appreciate it immensely.
I should have qualified my request for "unique identifiers" since for
this variable (obs) - it isn't strictly necessary (although it would be
nice). I do have a true unique identifier id (1-910) which is ordered
1-910 by subject 1-26/attribute 1-35. The obs var will only be used to
keep additional track of manual input of binary values (0's and 1's)
from printouts - eg. I'll know for example that id#600 = obs 213 and is
probably subject #21 attribute#3 and not subject #2 attribute #13. I'm
certain that this might be considered a very silly and/or inefficent way
to keep track, but so far it seems quick and dirty for so much manual
input of data. We can identify which printout, which subject, which
attribute... at a glance.
Creating obs as a string variable seems the overall best approach for
our specific purposes as recommended by Nick and shown below.
Although we aren't allowed to overindulge/say too much on statalist
outside the specified question, I do want to add how much easier and
pleasant it makes life for those of us without a hint of computer
logic/programming knowledge or understanding. To have such patient,
willing, able, and expert help often within moments is a beautiful thing!!
Thanks again!
Suzy
Nick Cox wrote:
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/
*
* 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/