Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: AW: Error in egen rank(), unique?


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: AW: Error in egen rank(), unique?
Date   Tue, 3 Nov 2009 13:18:02 +0100

<> 

No problem occur in this code, so where is the material difference to yours?

*************
clear*
set obs 10

gen id=_n  
gen dbep1=5+int(10*runiform())
gen dbep2=5+int(10*runiform())
gen deep1=5+int(10*runiform())
gen deep2=5+int(10*runiform())
gen durep1=rnormal()
gen durep2=rnormal()

reshape long dbep deep durep, i(id) j(episode)
by id, sort: egen rank_dbep = rank(dbep), unique
by id, sort: egen rank_deep = rank(deep), unique
by id, sort: replace rank_dbep =_n if rank_dbep[_n] == .
sort id rank_dbep
drop episode
reshape wide dbep deep durep rank_deep, i(id) j(rank_dbep)
*************

You do change the values returned by -egen, rank()- with your -replace-
line, so it is hard to argue that -egen- is at fault. Still, the line
clearly intends to replace the rank by its running number if it is missing.
So insert something like -inspect rank_dbep- before that line to see whether
there are any missings in the first place.

Also note that the -if rank_dbep[_n] == .- qualifier could easily be - if
rank_dbep == .-...


HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Kaulisch, Marc
Gesendet: Dienstag, 3. November 2009 11:27
An: [email protected]
Betreff: st: Error in egen rank(), unique?

I have a problem with an egen rank(), unique command (Stata version 10.1).
It looks like it does not produce the unique values as I like.
 
This is my start to rank episodes by their beginning (dbep). First I reshape
the dataset into the long-format.
 
. reshape long dbep deep durep, i(id) j(episode)
 
. by id, sort: egen rank_dbep = rank(dbep), unique
. by id, sort: egen rank_deep = rank(deep), unique
 
. by id, sort: replace rank_dbep = _n if rank_dbep[_n] == .
 
. sort id rank_dbep
 
When I do want to transform this dataset back in the wide format:
 
. drop episode
 
. reshape wide dbep deep durep rank_deep , i(id) j(rank_dbep)
 
I receive the following error:
 
rank_dbep not unique within id;
there are multiple observations at the same rank_dbep within id.
Type "reshape error" for a listing of the problem observations.
r(9);
 
reshape error gives out the number of 15 cases in which rank_dbep is not
unique.
 
Strangely enough with a different dataset the same commands work just fine.
 
Any ideas?
 


Marc Kaulisch

 
iFQ
Institut für Forschungsinformation und Qualitätssicherung
Godesberger Allee 90
53175 Bonn, Germany
Tel.: *49 - 228 - 9 72 73 - 25
Fax: *49 - 228 - 9 72 73 - 49
E-mail: [email protected]
www.forschungsinfo.de

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


*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index