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

[no subject]

From   Patrick Joly <>
Date   Wed, 6 Nov 2002 23:50:26 -0500

In my earlier posting, I wrote
> -xpose- seems to object when the _varname variable contains the
> string values v1, v2, ..., vN.  For instance,
> <snip>
> . list
>      _varname      myvar
> 1.         v1          1
> 2.         v2          2
> 3.         v3          3
> 4.         v4          4
> 5.         v5          5
> <snip>
> . xpose, clear
> v1 already defined
> r(110);

and Scott Merryman replied
> Perhaps the problem is not the values of the variable
> but the variable name.
> If you rename _varname xpose seems to work.

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,

1.       v5
2.       v9
3.      foo
4.      boo
5.       v3
6.     blah

and I should have made that clear in my earlier posting.  Invoking -
xpose- with the above values, Stata would balk and tell me that either 
v5, v9 or v3 already exists when in fact this isn't true. 

Consider this slightly modified example,

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

Feature or bug?  Looks like the latter to me since all values are 
perfectly legitimate variable names.

I also wrote yesterday that situations similar to these arise for me 
because I must: 1) load data which does not necessarily contain names 
for each variable (via -insheet-), some do some don't; 2) transpose it 
once; 3) perform certain operations; and 4) transpose it again.  I 
cannot append a prefix or a suffix to the string values in _varname 
since some may already be at the 32-character limit for names.

Pat Joly

*   For searches and help try:

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