It's quicker to do it than to explain you're not going to do it!
forval j = 1/`nobs' {
capture rename _var`j' `= _var`j'[1]'
}
Could become
forval j = 1/`nobs' {
capture rename _var`j' `= _var`j'[1]'
noi if _rc {
di `"note: problem with name `=
_var`j'[1]'"'
}
}
Nick
[email protected]
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Richard
Goldstein
Sent: 19 May 2009 14:26
To: [email protected]
Subject: Re: [Fwd: Re: st: from value to varnames]
thank you St. Nick!
I did use subinstr to replace the hyphens, but with underscores rather
than spaces
I still think that sxpose should pass the Stata error message thru when
there is a "flaw" in the data that prevents the rename (but I am not
going to produce a new version to do this!)
Rich
Nick Cox wrote:
> As Phil Schumm half-stated earlier, I am the author of -sxpose-, which
> is on SSC. (There are other Nicks, old and young.)
>
> There is only version of -sxpose-, 1.0.0.
>
> The help warns
>
> -firstnames- specifies that the first variable (first column) in the
> existing dataset is to be treated as a set of variable names for the
> variables in the transposed dataset. This first column will not appear
> as the first observation in the new dataset. Any values that are not
> legal variable names will be lost.
>
> Ideally, Rich can just get rid of his hyphens by
>
> replace field = subinstr(field, "-", "", .)
>
> Another thing to look out for that the values of -field- are all
> distinct. There are several ways to check that. There is a survey in
>
> SJ-8-4 dm0042 . . . . . . . . . . . . Speaking Stata: Distinct
> observations
> (help distinct if installed) . . . . . . N. J. Cox and G. M.
> Longton
> Q4/08 SJ 8(4):557--568
> shows how to answer questions about distinct observations
> from first principles; provides a convenience command
>
> Nick
> [email protected]
>
> Richard Goldstein
>
> data error -- it turns out that some of the strings in "field"
contained
>
> hypthens -- since varnames cannot contain hyphens, sxpose would not do
> the rename -- but gave me no error message -- sorry for the confusion
>
> From: Richard Goldstein <[email protected]>
>
> not on my machine -- I even downloaded a new copy of sxpose (from ssc)
> and did exactly what you suggested (via cut-and-paste) and the new
> varnames are _var# (258 of them)
>
> so ...
>
> Phil Schumm wrote:
>> On May 18, 2009, at 8:19 PM, Richard Goldstein wrote:
>>> nope -- Nick's -sxpose- gives me variables with varnames _var1, etc
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/