Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: dlist command


From   "Holly Wright" <hwright16@hotmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: dlist command
Date   Fri, 21 Jul 2006 20:16:29 +0000

I have modified dlist.ado so that I can use it to do a side by side
comparison of some duplicates in my data.  The only hitich is that I can't
figure out how to format the second record so it lines up nicely.

Nick, would you be so kind?

*! 1.3.0 NJC 8 Feb 2006
* 1.2.0 NJC 7 Feb 2006
* 1.1.0 NJC 7 Feb 2006
* 1.0.0 NJC 7 Feb 2006
program dlist2, byable(recall)
	version 8.2
	syntax [varlist] [if] [in] ///
	[, noLabel Name(int 32) Varlabel(int 80) Spaces(int 3) ]


	marksample touse, novarlist
	qui count if `touse'
	if r(N) == 0 error 2000

	// variable name width and variable label width
	local nam = 0
	local var = 0
	foreach v of local varlist {
		local nam = max(`nam', length("`v'"))
		local var = max(`var', length(trim(`"`: variable label `v''"')))
	}

	local nam = min(`name', `nam')
	local var = min(`varlabel', `var')

	// spaces is number of spaces between columns
	local col2 = cond(`nam' == 0, 1, `nam' + `spaces' + 1)
	local col3 = `col2' + cond(`var' == 0, 0, `var' + `spaces' + 1)

	tempvar which
	gen long `which' = _n
	qui levels `which' if `touse', local(levels)

	foreach l of local levels {
          if mod(`l',2)==1 {
		di _n as txt "`l'."
		foreach v of local varlist {
			if "`label'" != "" | "`: value label `v''" == "" {
				local show : di `: format `v'' `v'[`l'] _skip(20)  `: format `v''
`v'[`l'+1]
				capture confirm numeric variable `v'
				if _rc == 0 local show = trim(`"`show'"')
			}
			else {
				local show `"`: label (`v') `=`v'[`l']'  `v'[`l'+1]'"'
			}

			di as txt cond(`nam' > 0, abbrev("`v'", `nam'), "") ///
			"{col `col2'}" as txt ///
	cond(`var' > 0, abbrev(trim(`"`: var label `v''"'), `var'), "") ///
			"{col `col3'}" as res "`show'"
		}
		}
	}
end


*
*   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/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index