| |
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: creating unique identifier values
At 09:06 PM 3/8/2006, you wrote:
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
}
}
Austin beat me to it. My solution was
clear
set obs 910
gen id = 0
local casenum = 0
forval i = 1/26 {
forval j = 1/35 {
local casenum = `casenum' + 1
if `j' < 10 {
quietly replace id = `i' * 10 + `j' in `casenum'
}
else {
quietly replace id = `i' * 100 + `j' in `casenum'
}
}
}
BUT, are you sure you want to do it this way??? Note that you DO NOT
get unique ids this way. For example, 211 shows up twice - once with
case 2, attribute 11, and again with case 21, attribute 1. Where I
have `i' * 10 above, I would make it `i' * 100 (The code could be
simplified further, of course). i.e. make it 100* subject number +
attribute number.
-------------------------------------------
Richard Williams, Notre Dame Dept of Sociology
OFFICE: (574)631-6668, (574)631-6463
FAX: (574)288-4373
HOME: (574)289-5227
EMAIL: [email protected]
WWW (personal): http://www.nd.edu/~rwilliam
WWW (department): http://www.nd.edu/~soc
*
* 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/