Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: how to copy rows according to comma separated variable


From   Maarten buis <[email protected]>
To   [email protected]
Subject   Re: st: how to copy rows according to comma separated variable
Date   Thu, 21 Dec 2006 10:36:42 +0000 (GMT)

--- "FUKUGAWA, N." <[email protected]> wrote:
> i need to transform the data as follows.
> 
> the current data
> id	x
> 1	100; 105
> 2	245
> 3	2119; 309; 1054
> 4	3
> 5	30006; 14
> 
> the modified data
> id	x
> 1	100
> 1	105
> 2	245
> 3	2119
> 3	309
> 3	1054
> 4	3
> 5	30006
> 5	14
> 
> the data has several variables (string and numerical) and "x" is
> only variable that is comma separated.
> information of other variables needs to be retained after
> modification.

Your question involves two steps:
1) split up the variable x, which can be done with the aptly named
-split- command, see -findit split-. 
2) Reshape the data so that the new variables are below one another,
which can be done with the -reshape command-.

See the example below:

*---------- begin example ------------
/*get the data in*/
clear
input id	str20 x
1	"100; 105"
2	"245"
3	"2119; 309; 1054"
4	"3
5	"30006; 14"
end
list

/*step 1*/
split x, parse(";") gen(z) destring
list

/*step 2*/
reshape long z, i(id) j(year)
list 
*----------- end example -------------

Hope this helps,
Maarten


-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands

visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434

+31 20 5986715

http://home.fsw.vu.nl/m.buis/
-----------------------------------------


		
___________________________________________________________ 
Now you can scan emails quickly with a reading pane. Get the new Yahoo! Mail. http://uk.docs.yahoo.com/nowyoucan.html
*
*   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