Statalist


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

Re: st: Reshape-like procedure - help!


From   Ulrich Kohler <[email protected]>
To   [email protected]
Subject   Re: st: Reshape-like procedure - help!
Date   Tue, 13 Jan 2009 16:49:09 +0100

Am Dienstag, den 13.01.2009, 15:37 +0000 schrieb K Jensen:
> Hi
> 
> I would like to move from the following format
> ID	Age	Weight	Height
> 1	23	140	62
> 2	64	96	72
> 3	49	123	67
> 
> To this format:
> ID	Var_name	Var_value
> 1	Age	23
> 1	Weight	140
> 1	Height	62
> 2	Age	64
> 2	Weight	96
> 2	Height	72
> 3	Age	49
> 3	Weight	123
> 3	Height	67
> 
> How can I do this in Stata? None of reshape, stack or xpose are
> exactly what I need.
> 
> In reality I have over 100 variables rather than three--so I would
> like to avoid having to list the variables by name if possible.


local i 1
foreach var of varlist Age-Height {
	local lab`i' `var'
	ren `var' var`i++'
}
reshape long var, i(ID) j(Var_name)
lab val Var_name names
forv j = 1/`--i' {
	lab def names `j' "`lab`j''", modify
}






-- 
[email protected]
030 25491-361

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