Caleb,
Shouldn't "dessent,harold" come before "massagli,mark" ?
Here is one way that uses Mata (and Ben Jann's -moremata-)
clear
input str20 x1 str20 x2 str20 x3
"massagli,mark" "wood,j." "dessent,harold"
"beletz,elaine" "carter,annie" "curtis,barbara"
"bradshaw,joe" "brown,arnold" "dunaway,lowell"
"schneider,mark" "mullins,bobby" "sump,lawrence"
end
tempfile foo
mata
C= J(3,1,"")
A = st_sdata(.,.)'
for (i = 1; i <=cols(A); i++) {
A = sort(A,i)
C = C,A[.,i]
}
C=C[.,(2::cols(A)+1)]'
mm_outsheet("`foo'",C, mode="r")
end
set trace off
insheet using `foo', clear tab
l
Scott
> -----Original Message-----
> From: [email protected] [mailto:owner-
> [email protected]] On Behalf Of Caleb Southworth
> Sent: Tuesday, September 05, 2006 5:55 PM
> To: [email protected]
> Subject: st: sort strings within rows
>
> I would like to sort data within a set of variables (within a row). The
> set of variables describe officer names, surname first. For example, some
> of the data are
>
> | tvp1 tvp2 tvp3 |
> |------------------------------------------------------------------|
> 466. | massagli,mark wood,j. dessent,harold |
> 476. | beletz,elaine carter,annie curtis,barbara |
> 484. | bradshaw,joe brown,arnold dunaway,lowell |
> 497. | schneider,mark mullins,bobby sump,lawrence |
>
>
> The desired outcome is
>
> | tvp1 tvp2 tvp3 |
> |------------------------------------------------------------------|
> 466. | massagli,mark dessent,harold wood,j. |
> 476. | beletz,elaine carter,annie curtis,barbara |
> 484. | bradshaw,joe brown,arnold dunaway,lowell |
> 497. | mullins,bobby schneider,mark sump,lawrence |
>
> such that the id number remains the same and the data are shuffled within
> the tvp# variables. This will permit an assessment of change in officers
> between years without looping over all the variables of a similar type
> (i.e. vice presidents or presidents).
>
> I considered using reshape, but at least in my hands that leads to a very
> long kludge.
>
> Thanks!
>
> Caleb
*
* 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/