Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: list long string variables in Stata8.2 SE


From   Arnold Kester <[email protected]>
To   [email protected]
Subject   Re: st: list long string variables in Stata8.2 SE
Date   Mon, 01 Mar 2004 09:52:22 +0100

Thanks. I knew I was doing something clumsy. I never thought of using -display- to list the data. And I didn't have the acquaintance of -piece-, obviously.

Michael Blasnik wrote:

I couldn't resist a quick stab at making this shorter and easier (without
preserving the data, reshaping,etc.)  The main short-cut is to use the
extended macro function -piece-.  Here's some code to do the basic id
variable plus list a long string.  I haven't put in anything to display more
than 2 variables and haven't dealt with value labels (add 2 lines of code),
but here's the basic approach:

program define listlong2
version 8.2
syntax varlist(min=2) [if] [in] [,Indent(integer 10) Length(integer 60)]
gettoken patnr varlist: varlist
gettoken stringvar varlist: varlist
marksample touse, novarlist
markout `touse' `patnr' `stringvar', strok
qui count if `touse'
local start=_N-r(N)+1
local end=_N
local maxpieces=ceil(244/`length')
sort `touse' `patnr'
forval i=`start'(1)`end' {
local id=`patnr'[`i']
local idlen=length("`id'")
local indent=max(`indent',`idlen'+1)
local pad=`indent'-`idlen'
local string=`stringvar'[`i']
forval j=1(1)`maxpieces' {
 local part`j': piece `j' `length' of `"`string'"'
 if `j'==1 di "`id'" _skip(`pad') `"`part`j'"'
 else if `"`part`j''"'!="" di _skip(`indent') `"`part`j'"'
}
}
end

Michael Blasnik
[email protected]

[snip]
--
Met vriendelijke groet,
Arnold Kester

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index