program define varxplor *! version 1.0.0 <04Jul98> STB-45 dm61 ** Author: John R. Gleason, Syracuse University, Syracuse NY, USA ** (loesljrg@ican.net) version 5.0 window control clear macro drop DB* /* default launch button assignments, left-to-right */ local ButCmd "Notes inspect codebook summarize describe" /* default placeholder */ global DB_Place "?" global DB_DBuf 6 local varlist "opt" local options /* */ "Alpha B1(string) B2(string) B3(string) B4(string) B5(string)" parse "`*'" global DB_var "`varlist'" if "`alpha'" == "" { local Alpha "*" } else qui { global DB_NV1 : word count `varlist' preserve drop _all set obs $DB_NV1 gen str8 vname = "" } parse "`varlist'", parse(" ") local i 1 while "``i''" != "" { global DB_v`i' "``i''" `Alpha' qui replace vname = "``i''" in `i' local i = `i' + 1 } global DB_NV1 = `i' - 1 if "`alpha'" != "" { gen int kase = _n sort vname local i 0 while `i' < $DB_NV1 { local i = `i' + 1 global DB_v`i' = "${DB_v`i'} " + vname[`i'] + /* */ " " + string(kase[`i']) } restore } global DB_DBuf = min($DB_NV1, $DB_DBuf) local i 0 local j 5 while `i' < 5 { local i = `i' + 1 if "`b`i''" == "" { local b`i' : word `i' of `ButCmd' } local a : word 2 of `b`i'' if "`a'" == "" { local b`i' "`b`i'' $DB_Place" } local a : word 1 of `b`i'' global DB_But`i' "Command `b`i''" window control button "(`a')" `j' 22 52 9 DB_But`i' local j = `j' + 52 } global DB_savd " " global DB_NPW " " window control static DB_NPW 5 3 280 8 left window control static DB_sav 5 11 45 8 left global DB_sort window control static DB_sort 52 11 233 8 left global DB_ex "exit 3000" window control button "Exit" 287 4 30 9 DB_ex escape global DB_hlp "whelp varxplor" window control button "Help" 287 13 30 9 DB_hlp help window control scombo DB_var 42 32 64 85 DB_VarX global DB_Vsel "FVar" window control button "Locate" 5 32 33 9 DB_Vsel global DB_Upd "Draw" window control button "Refresh" 5 42 33 9 DB_Upd global DB_Vn1 "Variable" window control static DB_Vn1 45 43 32 8 left global DB_Alph 0 /* Must be there, in both modes! */ `Alpha' window control check "abc..." 79 43 30 8 DB_Alph global DB_Cmd "Command \$DB_CmdX" window control button "" 287 22 30 9 DB_Cmd default window control edit 112 33 205 8 DB_CmdX window control radbegin "Data Type" 112 43 48 8 DB_Vptr window control radio "Format" 162 43 37 8 DB_Vptr window control radio "Value Label" 201 43 53 8 DB_Vptr window control radend "Variable Label" 256 43 61 8 DB_Vptr global DB_Vptr 4 window control static DB_NV1 5 52 312 60 blackframe window control static DB_NV1 41 52 67 60 blackframe local i 0 local j 56 while `i' < $DB_DBuf { local i = `i' + 1 window control static DBVnam`i' 45 `j' 61 8 left window control static DB_buf`i' 112 `j' 203 8 left local j = `j' + 9 } global DB_Top "Scroll 0" window control button "Top" 8 55 30 9 DB_Top global DB_PgUp "Scroll -$DB_DBuf" window control button "PgUp" 8 64 30 9 DB_PgUp global DB_Up "Scroll -1" window control button "Up" 8 73 30 9 DB_Up global DB_Dn "Scroll 1" window control button "Dn" 8 82 30 9 DB_Dn global DB_PgDn "Scroll $DB_DBuf" window control button "PgDn" 8 91 30 9 DB_PgDn global DB_Bot "Scroll ." window control button "Bottom" 8 100 30 9 DB_Bot Draw 1 capture noi window dialog "VarXplor > $S_FN" . . 326 126 macro drop DB* exit 0 end program define Scroll local t `1' if "`1'" == "." { local t = $DB_NV1-$DB_DBuf+1 } else if "`1'" != "0" { local t = `1' + $DB_Buf1 } local t = min($DB_NV1-$DB_DBuf+1, `t') local t = max(1, `t') Draw `t' end program define Draw if "`1'" != "" { global DB_Buf1 `1' } local i $DB_Buf1 local j 0 local Vwd 1 if "$DB_Alph" == "1" { local Vwd 2 } local keys "type format value variable" local K : word $DB_Vptr of `keys' if $DB_Vptr > 2 { local K "`K' label" } while `j' < $DB_DBuf { local j = `j' + 1 local vn : word `Vwd' of ${DB_v`i'} local T : char `vn'[note0] if "`T'" != "" { local T " *" } global DBVnam`j' "`vn'`T'" local t : `K' `vn' global DB_buf`j' "`t' " local i = `i' + 1 } global DB_VarX : word 1 of $DBVnam1 Info end program define FVar cap Unabb $DB_VarX if _rc { window stopbox stop /* */ "'$DB_VarX '" "is either an ambiguous name" /* */ "or not a current variable name" exit } local t "$S_1" local A : word 2 of $DB_v1 if "`A'" != "" { local i 1 local j $DB_NV1 while `i' < `j' { local k = int(`i'+`j'+1)/2 local V : word 2 of ${DB_v`k'} if "`t'" < "`V'" { local j = `k' - 1 } else if "`t'" > "`V'" { local i = `k' + 1 } else { local i = `k' local j = `k' } } } else { local i 0 local done 0 while (`i' < $DB_NV1) & (!`done') { local i = `i' + 1 local done = ("`t'" == "${DB_v`i'}") } if !`done' { window stopbox stop "Variable `t'" "not found" exit } } if "`A'" != "" & "$DB_Alph" == "0" { local i : word 3 of ${DB_v`i'} } Scroll `i'-$DB_Buf1 end program define Notes local nn : char `1'[note0] if "`nn'" == "" { exit } di in ye _new "`1':" local i 1 while `i' <= `nn' { local b : char `1'[note`i'] if "`b'" != "" { di in gr %4.0g " `i'. ", "`b'" } local i = `i' + 1 } end program define Unabb local varlist "req ex" parse "`*'" global S_1 : word 1 of `varlist' end program define Command parse "`*'", parse(" ,") local b "dropkeepmoveorderexit" local i 1 while "``i''" != "" { local a "``i''" if (`i'==1) | ("`1'" == "by") { if index("`b'", "`a'") { window stopbox stop "`a' not allowed" exit } } local t = index("`a'", "$DB_Place") if `t' { if "$DB_VarX" == "" { exit } local `i' = substr("`a'", 1, `t'-1) + "$DB_VarX" /* */ + substr("`a'", `t'+1, .) } local i = `i' + 1 } if "`1'" != "Notes" { window push `*' di in wh _new ". `*'" } `*' Info end program define Info qui describe local a = _result(1) local b = _result(2) local c = _result(3) global DB_sav if _result(7) { global DB_sav "NOT SAVED" } global DB_NPW "Obs: `a' Vars: $DB_NV1 (of `b') Width: `c'" global DB_NPW "Last saved: $S_FNDATE $DB_NPW" global DB_sort : sortedby global DB_sort "Sorted by: $DB_sort" end