Statalist The Stata Listserver


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

st: re: Shuffling elements of a string variable within cases


From   Kit Baum <[email protected]>
To   [email protected]
Subject   st: re: Shuffling elements of a string variable within cases
Date   Tue, 16 Jan 2007 20:52:26 -0500

Someone on the Mata development team must spend some time in Las Vegas...

clear
input str6 var1
abcdef
abcdef
abcdef
end

l var1

program drop _all
program shufstr
version 9.2
syntax varlist(string max=1)
mata: shufstr("`varlist'")
end

mata: mata clear
mata:
void function shufstr(string vector vname)
{
st_sview(S=.,.,vname)
for(i=1; i<= rows(S); i++) {
S[i,.]=char(jumble(ascii(S[i,.])')')
}
}
end

shufstr var1
l var1
shufstr var1
l var1


Kit Baum, Boston College Economics
http://ideas.repec.org/e/pba1.html
An Introduction to Modern Econometrics Using Stata:
http://www.stata-press.com/books/imeus.html


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