*! version 1.1.1 12Nov95 (STB-29: gr18) program define parcoord version 4.0 local varlist "req ex min(2)" local if "opt" local in "opt" local options "BY(string) CENter COLorby(string) Echo TOUR *" parse "`*'" parse "`varlist'", parse(" ") qui describe if _result(7) { error 4 } tempname bv cen cv scalar `bv' = ("`by'" != "") if `bv' { confirm variable `by' } scalar `cv' = ("`colorby'" != "") if `cv' { qui inspect `colorby' if _result(7) > 19 { error 134 } scalar `cv' = _result(7) } tempvar touse mark `touse' `if' `in' markout `touse' `varlist' `by' `colorby' qui count if `touse' if !_result(1) { error 2000 } preserve global S_FN "" qui keep if `touse' keep `varlist' `by' `colorby' qui compress scalar `cen' = ("`center'" != "") if `cen' { local center ", d" } local i = 1 qui while "``i''" != "" { local nn : type ``i'' if substr("`nn'", 1, 3) == "str" { error 108 } summ ``i'' `center' if `cen' { replace ``i'' = 1 + (``i''-_result(10))/ /* */ max(_result(6)-_result(10), _result(10)-_result(5)) } else { replace ``i'' = 2*(``i''-_result(5))/(_result(6)-_result(5)) } if "`nn'" == "double" { tempvar vv gen float `vv' = ``i'' drop ``i'' rename `vv' ``i'' } if mod(`i', 2) { local xl "`xl',`i'" } else { local tl "`tl', `i'" } local Xlab "`Xlab' `i' ``i''" local i = `i' + 1 } local Nv = `i' - 1 local xl = substr("`xl'", 2, .) local xlab "`xl'" if `Nv' > 9 { local tlab = "tlab(" + substr("`tl'", 2, .) + ")"} else { local xlab "`xl'`tl'" } local nn = _N local symch "p" if `bv' { tempname btw btk btp scalar `btw' = 69 scalar `btp' = `Nv' local symch "i" } local i = 2 qui while "``i''" != "" { local n1 = _N + 1 local newn = `nn' + _N capture set obs `newn' if _rc { describe local MaxV = _result(5) local MaxW = _result(6) local CurV = _result(2) + `cv' + 4 local CurW = _result(3) + `cv'*4 + 10 tempfile TFil save `TFil', replace drop _all set maxvar `CurV' width `CurW' use `TFil' set obs `newn' } replace `1' = ``i''[_n-`n1'+1] in `n1'/`newn' if `cv' { replace `colorby' = `colorby'[_n-`n1'+1] in `n1'/`newn' } if `bv' { replace `by' = `by'[_n-`n1'+1] in `n1'/`newn' scalar `btk' = min(8, round(`btw'/`btp',1) - 1) local b2t = "`b2t' " + substr("``i''", 1, `btk') scalar `btw' = `btw' - `btk' - 1 scalar `btp' = `btp' - 1 } if ("``i''"!="`colorby'") & ("``i''"!="`by'") { drop ``i'' } local i = `i' + 1 } if `bv' { local BY "by(`by')" local xlab "1, `Nv'" local tlab "" scalar `btk' = min(8, 69-length("`b2t'")) local b2t = substr("`1'",1, `btk') + " `b2t'" local B2T "b2(`b2t')" } tempname ParC1 ParC2 lab def `ParC2' 0 "Low" 2 "High" if `cen' { lab def `ParC2' 1 "Mdn", add local yline "yline(1)" local center "1," } lab val `1' `ParC2' if `cv' { qui tab `colorby', gen(CV) local i = 0 while `i' < `cv' { local i = `i' + 1 qui replace CV`i' = cond(CV`i', `1', .) local YY "`YY' CV`i'" local pens = "`pens'" + string(2 + mod(`i'-1, 8)) local L "`L'L" local sym "`sym'`symch'" } local pens "pen(`pens')" lab val CV1 `ParC2' } else { local YY "`1'" local L "L" local sym "i" } qui gen int xvar = 1 + int((_n-1)/`nn') lab var xvar " " /* could this be used to encode some information? */ qui gen long case = 1 + mod(_n-1, `nn') qui compress xvar case sort `by' case xvar scalar `cen' = 1 while `cen' { qui if "`tour'" != "" { if `cen' == 1 { local newn : type xvar gen `newn' Xvar = xvar gen int txv = 1 replace txv = mod(txv[_n-1]+(xvar-1)*(-1)^xvar,`Nv') if xvar != 1 replace txv = `Nv' + txv if txv <= 0 } else { sort `by' case Xvar replace txv = cond(txv == `Nv'-1, `Nv', mod(txv+1, `Nv')) } local newn "" local B2T "" local i = 0 while `i' < `Nv' { local i = `i' + 1 local newn "`newn' `i'" local n1 = txv[`i'] replace xvar = `i' in `n1' local symch : word `n1' of `b2t' local B2T "`B2T' `symch'" local n1 = 2 * `n1' local n1 : word `n1' of `Xlab' local newn "`newn' `n1'" } replace xvar = xvar[_n-`Nv'] if _n > `Nv' scalar `cen' = `cen' + 1 sort `by' case xvar if `bv' { local B2T "b2(`B2T')" } } else { scalar `cen' = 0 local newn `Xlab' } lab def `ParC1' `newn', modify lab val xvar `ParC1' if "`echo'" != "" { noi di "Variables: `newn'" } graph `YY' xvar, noaxis c(`L') sym(`sym') xline(`xl'`tl') xlab(`xlab') /* */ ylab(0,`center'2) `yline' `BY' `B2T' `pens' `tlab' /* */ `options' if `cen' { if "$S_OS"=="Windows" | "$S_OS"=="MacOS" { more } } } if "`MaxV'" != "" { drop _all set maxvar `MaxV' width `MaxW' } end