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

st: RE: RE: Re: generating new variable


From   "Ronnie Babigumira" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: Re: generating new variable
Date   Thu, 16 Jan 2003 17:31:54 +0100

Thanks Nick and Danielle
Nicks suggestion solves my problem (though as always I was intimidated by
one of the "for" cousins (foreach.. forval) but I am working on demystifying
them)

Ronnie

-----Original Message-----
From: [email protected]
[mailto:[email protected]]On Behalf Of Nick Cox
Sent: 16. januar 2003 17:00
To: [email protected]
Subject: st: RE: Re: generating new variable


Ronnie Babigumira

> > Happy new year (hope its not too late for this). I have
> some household data
> > with a number of variables indicating whether or not a
> household carried
> out
> > a given practice (cropre00 mulch00 grman00). An example
> is given below (1
> if
> > pursued, 0 otherwise)
> >
> > houscode  cropre00   mulch00   grman00
> > 12110001         0         0         0
> > 12110002         0         0         0
> > 12110003         1         0         0
> > 12401001         1         0         0
> > 12401002         0         0         0
> > 12401003         0         0         0
> > 12403001         0         0         0
> > 12403002         0         0         0
> > 12403003         1         0         0
> > 14110021         0         0         0
> >
> > I want to generate new variables
> > 1. npracts, which is the number of practices a household
> carried out
> > 2. A number of dummies eg
> >
> > oneprac "Household pursued atleast one practice"
> > twoprac "Household pursued atleast two practice"
> >

Danielle H. Ferry
>
> Use "egen" w/ the "sum" option.
>

Not quite. Ronnie first needs the -rsum()- function
of -egen-:

egen npracts = rsum(*00)

Any number of dummies then follow from

forval i = 1/<whatever> {
	gen byte prac`i' = npracts >= `i' & npracts < .
}

The naming scheme oneprac, twoprac, ... will be
more difficult downstream than one like that here.

Nick
[email protected]
*
*   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/



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