ch14.2.do open
file:script:do
| # | content |
|---|---|
| 1 [+] | * ITSP 14.2 |
| 3 [+] | sysuse auto , |
| 4 [+] | qui desc |
| 5 [+] | g model = "" |
| 6 [+] | forv i=1/`=r(N)' { |
| 7 [+] | local temp = make[`i'] |
| 8 [+] | local model: word 2 of `temp' |
| 9 [+] | qui replace model = "`model'" in `i' |
| 10 [+] | } |
| 11 [+] | keep in 1/15 |
| 12 [+] | keep make model price |
| 13 [+] | l make model |
| 14 [+] | save ch14.2 , |
/* program drop _all program shufstr version 10.1 syntax varlist(string max=1) mata: shufstr("`varlist'") end version 10.1 mata: mata clear |
|
| 25 [+] | mata block (10 lines) |
*/ |
|
| 36 [+] | type shufstr.ado |
| 38 [+] | do shufstr.mata |
| 40 [+] | type shufstr.mata |
| 42 [+] | clear |
| 43 [+] | sysuse auto , |
| 44 [+] | generate model = "" |
| 45 [+] | quietly describe |
| 46 [+] | forvalues i = 1/`=r(N)' { |
| 47 [+] | local temp = make[`i'] |
| 48 [+] | local model: word 2 of `temp' |
| 49 [+] | qui replace model = "`model'" in `i' |
| 50 [+] | } |
| 51 [+] | keep in 1/15 |
| 52 [+] | keep make model price |
| 53 [+] | generate shufmod = model |
| 54 [+] | set seed 20080906 |
| 55 [+] | shufstr(shufmod) |
| 56 [+] | list , |
* ITSP 14.2
sysuse auto,clear
qui desc
g model = ""
forv i=1/`=r(N)' {
local temp = make[`i']
local model: word 2 of `temp'
qui replace model = "`model'" in `i'
}
keep in 1/15
keep make model price
l make model
save ch14.2,replace
/*
program drop _all
program shufstr
version 10.1
syntax varlist(string max=1)
mata: shufstr("`varlist'")
end
version 10.1
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
*/
type shufstr.ado
do shufstr.mata
type shufstr.mata
clear
sysuse auto, clear
generate model = ""
quietly describe
forvalues i = 1/`=r(N)' {
local temp = make[`i']
local model: word 2 of `temp'
qui replace model = "`model'" in `i'
}
keep in 1/15
keep make model price
generate shufmod = model
set seed 20080906
shufstr(shufmod)
list, sep(0) noobs