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

From |
David Kantor <kantor.d@att.net> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: question related to collapse |

Date |
Thu, 04 Dec 2008 20:11:25 -0500 |

At 06:36 PM 12/4/2008, Laura Grigolon wrote:

Dear Statalister,I have a dataset with several variables, among which a discretevariable X that looks as follows.------------------- X obs1 60 obs2 60 obs3 60 obs4 70 obs5 71 obs6 71 obs7 71 obs8 71 obs9 71 obs10 71 --------------------My final purpose is to treat adjacent observations for which thevariable X does not change by more than 10% as the same observation.In other words, I would like to collapse the dataset by X, butwhenever the distance between two or more adjacent observations in Xis less than 10%, I would like to collapse by a median of x. Beforecollapsing I tried to generate a median of X whenever thedifference within X is less than 10%, and then collapse by X, but Iam not succeding. Is this the right approach? Is there a way ofcollapsing specifying my requirement?Thank you in advance, Laura

60, 65, 70 65 is within 10% of 60; 70 is within 10% of 65; but 70 is not within 10% of 60.

Another example: 901, 1000 -- no, 1000 is not within 10% of 901. 1000, 901 -- yes, 901 is within 10% of 1000.

Again, the order matters.

If so, then you can do something like this (untested): gen byte w10pct = abs(X/X[_n-1] -1) < .1 & _n >1 gen int cluster_id = sum(w10pct ==0)

HTH --David

Good luck. --David * * 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/

**References**:**st: question related to collapse***From:*"Grigolon, Laura" <Laura.Grigolon@econ.kuleuven.be>

- Prev by Date:
**st: question related to collapse** - Next by Date:
**st: ksmirnov on Johnson SB** - Previous by thread:
**st: question related to collapse** - Next by thread:
**RE: Re: st: question related to collapse** - Index(es):

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