[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: re: Shuffling elements of a string variable within cases
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/