Statalist The Stata Listserver


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

RE: st: RE: data management problem


From   Maarten buis <[email protected]>
To   [email protected]
Subject   RE: st: RE: data management problem
Date   Sun, 6 May 2007 11:58:39 +0100 (BST)

I was about to leave for a walk, but two quick suggestion:

Starting by copying the example I sent and than generalizing it step by
step to your data is typically easier to debug. The example works, so
you can quickly see at which step the error occurs. 

Yes, it doesn't take care of repeated values. It probably quite easy to
do that by using one or more of the string functions, see: 
-help string functions-.

Hope this helps,
Maarten

--- Wanli Zhao <[email protected]> wrote:

> I tried the solution and I got some errors. First it says local
> option not
> allowed. Then I change the Ndepts to a variable I have which is the
> number
> of departments for each firm. Still does not work. Also it says my
> dataset
> is already wide.
> It also seems that the code does not take into account of repeated
> values in
> products. I am not sure about blanks in product column. Any
> suggestions?
> Willie
> 
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On Behalf Of Maarten
> buis
> Sent: Sunday, May 06, 2007 5:14 AM
> To: [email protected]
> Subject: Re: st: RE: data management problem
> 
> --- Wanli Zhao <[email protected]> wrote:
> > The data looks like follows:
> > 
> > firm	dept	product
> > 1	a	a, b
> > 1	b	c, r
> > 1	c	d, a
> > 2	d	d, f
> > 2	e	I, y
> > 2	f	g
> > 
> > Firm 1 & 2 each has some departments. Each department has some
> > products. I want to a variable which lists all the products a firm
> > has (a, b, c, d, r for firm 1) and for firm 2 (d, f, I, y, g). 
> 
> *----------- begin example --------------
> set more off
> drop _all
> 
> input firm	str1 dept	str4 product
> 1	a	"a, b"
> 1	b	"c, r"
> 1	c	"d, a"
> 2	d	"d, f"
> 2	e	"I, y"
> 2	f	"g"
> end
> 
> /*value one for the first department in each firm*/
> /*value two for the second department in each firm*/
> /*etc*/
> bys firm: gen deptnum = _n
> 
> /*store maximum number of department in local `Ndepts'*/
> sum deptnum, meanonly
> local Ndepts = r(max)
> 
> /*products of the first department are in variable products1*/
> /*products of the second department are in variable products2*/
> /*etc*/
> reshape wide product dept, i(firm) j(deptnum)
> 
> /*loop over departments*/
> gen prods = product1
> forvalues i = 2/`Ndepts' {
> 	replace prods = prods + ", " + product`i'
> }
> 
> /*bring the data back into original long format*/
> reshape long dept product, i(firm) j(deptnum)
> 
> /*show the result*/
> list, clean
> *-------------- end example ----------------
> (For more on how to use examples I sent to the Statalist, see:
> http://home.fsw.vu.nl/m.buis/stata/exampleFAQ.html )
> 
> 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/
> -----------------------------------------
> 
> 
>       ___________________________________________________________ 
> Yahoo! Mail is the world's favourite email. Don't settle for less,
> sign up
> for
> your free account today
>
http://uk.rd.yahoo.com/evt=44106/*http://uk.docs.yahoo.com/mail/winter07.htm
> l 
> *
> *   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/
> 
> *
> *   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/
> 


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


      ___________________________________________________________ 
Yahoo! Mail is the world's favourite email. Don't settle for less, sign up for
your free account today http://uk.rd.yahoo.com/evt=44106/*http://uk.docs.yahoo.com/mail/winter07.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