Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: flagging a specific pattern of values within observations


From   n j cox <[email protected]>
To   [email protected]
Subject   Re: st: flagging a specific pattern of values within observations
Date   Tue, 24 Apr 2007 23:18:24 +0100

Further comments:

1. -help macrolists-

2. Jeff Arnold included a Mata function as the heart of
his -sortrows- (SSC) for sorting rows. That requires
Stata 9.

3. This hand-made -egen- function will concatenate
and sort what is fed to it. Don't expect that decimal
places will all survive. Deprecate the loop over
observations. Sorts are alphabetic by default, or
optionally numeric.

Thus given -q421- ... -q427- that contain a shuffle
of 1(1)7, it will return "1 2 3 4 5 6 7".

*! NJC 1.0.0 24 April 2007
program _growsort
version 8
gettoken type 0 : 0
gettoken h 0 : 0
gettoken eqs 0 : 0

syntax varlist(min=1) [if] [in] [, BY(string) NUMeric]
if `"`by'"' != "" {
_egennoby rowsort() `"`by'"'
/* NOTREACHED */
}

tempvar g
marksample touse, strok
quietly {
egen `g' = concat(`varlist') if `touse', p(" ")
forval i = 1/`=_N' {
local value `=`g'[`i']'
if "`numeric'" != "" {
numlist "`value'", sort
replace `g' = "`r(numlist)'" in `i'
}
else {
local value : list sort value
replace `g' = "`value'" in `i'
}
}
// `type' ignored
}

gen `h' = `g' if `touse'
end

Nick
[email protected]

Sergiy Radyakin

So some questions for the Gurus:
-- how to subtract an element from a list?
-- does Stata support sets? (e.g. at the level of Pascal sets)
-- v1 v2 ...vn are chars: "a" "b" etc. Need X=concatenated sorted v1..vn.
E.g:

v1 v2 v3 X
a b c abc
b a c abc
a b a aab
a a a aaa

What is the shortest way? What if vi-s can be strings (not just chars)?
ab aa ca aaabca

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