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

From |
Alejandro Delafuente <alejandro.delafuente@st-antonys.oxford.ac.uk> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: RE: Specification for a 1/0 variable with consecutive non-missing observations |

Date |
Fri, 10 Jun 2005 18:21:11 +0100 (BST) |

Sorry to keep bothering you David. Actually I've got it how to number my observations: local i=1 foreach var of varlist ene1961-dic2000 { rename `var' `var'`i' local i = `i' + 1 } Now, I will let you know if your code works. In message <97D60F3695FA1A4E82535413AB0914A7375457@icnarc-app.icnarc.org> statalist@hsphsun2.harvard.edu writes: > Assuming your 40 variables are consecutively numbered in some way (here I have assumed var1-var40), the following (untested) code should be about right... > > gen cons=0 > gen maxcons=0 > forvalues i=1/40 { > replace cons=cons+1 if !missing(var`i') > replace cons=0 if missing(var`i') > replace maxcons=cons if cons>maxcons > } > gen byte cons20=maxcons>=20 > > The final variable (cons20) is the 1/0 variable you are after (maxcons will contain the longest run of consecutive non-missing variables). > > Hope this helps > > David > > -----Original Message----- > From: Alejandro Delafuente > [mailto:alejandro.delafuente@st-antonys.oxford.ac.uk] > Sent: 10 June 2005 16:23 > To: statalist@hsphsun2.harvard.edu > Subject: st: Specification for a 1/0 variable with consecutive > non-missing observations > > > Hi statalisters, > I have a time series for 40 years (40 continuos variables) and am trying to > create a 1/0 variable that indicates 1 (for each row) if at least 20 variables > in the series have consecutive non-missing values and 0 if this condition is > not accomplished. I do have more than 20 non-missing values for most of the > variables per row, but there are gaps (ie, missing values) between them. Thus I > want to know how many fulfill the condition of 20 non-missing values in a road. > Any clues as to how can I accomplish this with programming? > * > * 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/ > -- Alejandro de la Fuente QEH/Department of International Development Oxford University * * 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/

**References**:**st: RE: Specification for a 1/0 variable with consecutive non-missing observations***From:*"David Harrison" <david.harrison@icnarc.org>

- Prev by Date:
**Re: st: RE: Specification for a 1/0 variable with consecutive non-missing observations** - Next by Date:
**Re: st: RE: Specification for a 1/0 variable with consecutive non-missing observations** - Previous by thread:
**Re: st: RE: Specification for a 1/0 variable with consecutive non-missing observations** - Next by thread:
**Re: st: RE: Specification for a 1/0 variable with consecutive non-missing observations** - Index(es):

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