Statalist


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

st: AW: sort by permutation


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: AW: sort by permutation
Date   Mon, 21 Dec 2009 09:53:06 +0100

<> 

I could see mechanical solutions such as:


*************
clear*

input byte(id group)  
1    1
2    1
3    2
4    2
5    2
6    3
7    3
8    4
9    4
10  4
end

compress
list, noo

qui{
	levelsof group
		foreach lev in `r(levels)'{
			gen byte gr`lev'=group==`lev'
		}
}


sort gr2 group
l
sort gr1 group
l
sort gr4 group
l
sort gr3 group
l
sort gr3 gr2 group
l
*************

You can automate the selection of the combinations of groups via Nick`s -ssc
d selectvars-, although I cannot get it to work with -sort- in a -foreach-
loop at the moment...


HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Abdel Rahmen El
Lahga
Gesendet: Montag, 21. Dezember 2009 00:34
An: [email protected]
Betreff: st: sort by permutation

I have a sample of N individuals belonging to 4 sub-groups g1, g2, g3,
g4. I would like to sort my sample of size N  in 24 different
manners, corresponding to all possible permutations of my group
variable
say, {g1,g2,g3,g4}, {g1,g3,g2,g4} {g1,g3,g4,g2}...etc.
Taking a simple exemple for N=10. I have
id group
1    1
2    1
3    2
4    2
5    2
6    3
7    3
8    4
9    4
10  4

one possible sorting among 24 could be
id group
1    1
2    1
6    3
7    3
3    2
4    2
5    2
8    4
9    4
10  4
any help is apreciated
-- 
AbdelRahmen El Lahga
*
*   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