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

st: Re: RE: bug in xpose.ado?


From   "Scott Merryman" <[email protected]>
To   <[email protected]>
Subject   st: Re: RE: bug in xpose.ado?
Date   Thu, 7 Nov 2002 07:07:56 -0600

----- Original Message -----
From: "Patrick Joly" <[email protected]>
To: <[email protected]>
Sent: Wednesday, November 06, 2002 10:53 PM
Subject: st: RE: bug in xpose.ado?


> I meant to suggest that -xpose- complains when _varname takes on the
> string values "v" plus an integer.  Scott's suggestion is not a
> solution since -xpose- will only fetch the variable names from a
> variable called _varname if it "exists in the data before transposition
> (see help for xpose).  If it doesn't, Stata uses the generic names v1,
> v2, ..., vN.  Scott's example appeared to be solution because the
> variables names of the transposed data turned out to correspond to the
> rows of _varname.  But this was merely a fluke.  It occurred because
> the first observation of _varname was v1, the second was v2, etc.  But
> it needn't be so.  _varname could look like,
>
>    _varname
> 1.       v5
> 2.       v9
> 3.      foo
> 4.      boo
> 5.       v3
> 6.     blah
>
> Consider this slightly modified example,
>
> clear
> set seed 1234
> set type double
> set obs 10
> g str1 _varname = ""
> replace _varname = "v" + string(_n+5)
> replace _varname = "boo" in 3
> replace _varname = "foo" in 6
> g myvar = round(uniform()*10,1)
>
> . list
>
>       _varname       myvar
>   1.        v6           5
>   2.        v7           3
>   3.       boo           3
>   4.        v9           4
>   5.       v10           9
>   6.       foo           9
>   7.       v12           5
>   8.       v13           1
>   9.       v14           3
>  10.       v15           1
>
> . xpose, clear
> v6 already defined
> r(110);

Not that I understand why xpose chokes on the values of _varname but if you
rename it, xpose works with the modified example as well.  I realize this might
not be a general solution....

. clear

. set seed 1234
. set type double
. set obs 10
obs was 0, now 10
. g str1 _varname = ""
(10 missing values generated)
. replace _varname = "v" + string(_n+5)
_varname was str1 now str3
(10 real changes made)

. replace _varname = "boo" in 3
(1 real change made)
. replace _varname = "foo" in 6
(1 real change made)
. replace _varname = "abcdefghijklmnopqrstvwxyz123456780" in 10
_varname was str3 now str34
(1 real change made)
. g myvar = round(uniform()*10,1)


. list

                               _varname       myvar
  1.                                 v6           5
  2.                                 v7           3
  3.                                boo           3
  4.                                 v9           4
  5.                                v10           9
  6.                                foo           9
  7.                                v12           5
  8.                                v13           1
  9.                                v14           3
 10. abcdefghijklmnopqrstvwxyz123456780           1

. renpfix _v v
. xpose,clear
. list

             v1          v2          v3          v4          v5          v6
v7          v8          v9         v10
  1.          .           .           .           .           .           .
.           .           .           .
  2.          5           3           3           4           9           9
5           1           3           1



Scott



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