Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

AW: st: from value to varnames


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   AW: st: from value to varnames
Date   Tue, 19 May 2009 08:55:05 +0200

<> 

What is the difference btw your dataset and the one I made up on the fly?
Because with mine, Phil`s solution leads to the correct result:

*************
clear*

input str10 field        str5   cat order  
namea           A       1
nameb B 2
namec F 5
named T 12
end

compress
list, noobs

qui{
	gen value = cat + string(order)
	keep field value
	sxpose, clear force firstnames
}

l, noo

*************



HTH
Martin

-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Richard
Goldstein
Gesendet: Dienstag, 19. Mai 2009 03:19
An: [email protected]
Betreff: Re: st: from value to varnames


nope -- Nick's -sxpose- gives me variables with varnames _var1, etc -- 
which is of no use; sorry for not mentioning that I had already tried it

Rich

Phil Schumm wrote:
> On May 18, 2009, at 3:40 PM, Richard Goldstein wrote:
>> I have a data set with 3 variables: field, cat, order; there are 258 
>> observations
>>
>> I want the 258 observations in field to be 258 variables where the 
>> name of the value in field becomes the new variable name; I want to 
>> keep the associated values of the other two fields
>>
>> For example, say that the first observation has the following values:
>>
>> field        cat     order
>> namea        A    1
>>
>> I want a new set of variables such that I have a variable called 
>> "namea" and I still have cat (of "A") and order (of "1") -- but 
>> remember that I should now have 258 variables--cat and order can be 
>> joined as the value for each variable; thus, for the example above, 
>> the first variable (namea) would now have the value "A1"
> 
> 
> If you're interested in an off-the-shelf routine, then Nick's -sxpose- 
> will do the trick:
> 
> gen value = cat + string(order)
> keep field value
> sxpose, clear force firstnames
> 
> -- Phil
*
*   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/



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