*! Version 1.0.1 <09Aug1999> [STB-51: dm61.1] program define varxplor ** Author: John R. Gleason, Syracuse University, Syracuse NY, USA ** (loesljrg@accucom.net) local JRGver "1.0.1" version 6.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 "?" /* default size of command history buffer */ global DB_CBuf 20 syntax [varlist] [, Alpha B1(string asis) B2(string asis) /* */ B3(string asis ) B4(string asis) B5(string asis) ] /* DON'T mess with me! */ global DB_DBuf 6 tokenize `varlist' global DB_var "`*'" if "`alpha'" == "" { local Alpha "*" } else qui { global DB_NV1 : word count `varlist' preserve drop _all set obs $DB_NV1 gen str8 vname = "" } 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) global DB_Huhh "<_&!!&_>" 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'' $DB_Huhh"' 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 197 8 DB_CmdX global DB_C_up "CmdScr 0" global DB_C_dn "CmdScr 1" window control button " " 309 33 8 4 DB_C_up window control button " " 309 37 8 4 DB_C_dn global DB_CmdP0 0 global DB_CmdP1 0 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 `JRGver' > $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 "$DB_VarX" 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 syntax varlist global DB_VarX `varlist' end program define Command local C `"`*'"' local C : subinstr local C "$DB_Huhh" "", count(local But) local C : subinstr local C "$DB_Place" "$DB_VarX", /* */ all count(local i) if `i' > 0 & "$DB_VarX" == "" { window stopbox stop "No variable currently selected" exit } tokenize `"`C'"', parse(" :") local i 1 if "`1'" == "by" { while `"``i''"' != ":" { local i = `i' + 1 } local i = `i' + 1 } local b "aorder renpfix drop keep move order rename exit" local j : word count `b' while `j' > 0 { local a : word `j' of `b' if index("`a'", "``i''") { window stopbox stop "`a' not allowed" exit } local j = `j' - 1 } if `"`1'"' != "Notes" { window push `C' di in wh _new `". `C'"' } `C' Info if `But' { exit } global DB_CmdP0 = mod($DB_CmdP0 + 1, $DB_CBuf) global DB_Cm${DB_CmdP0} `"`0'"' global DB_CmdP1 $DB_CmdP0 end program define Info qui describe local a = r(N) local b = r(k) local c = r(width) global DB_sav if r(changed) { 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 program define CmdScr if `1' { global DB_CmdP1 = mod($DB_CmdP1 + 1, $DB_CBuf) } else { global DB_CmdP1 = -1+cond($DB_CmdP1>0, $DB_CmdP1, $DB_CBuf) } global DB_CmdX `"${DB_Cm${DB_CmdP1}}"' end