Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down at the end of May, and its replacement, **statalist.org** is already up and running.

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

From |
"Dherani, Mukesh" <M.K.Dherani@liverpool.ac.uk> |

To |
"statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |

Subject |
RE: st: using loop for [_n+1] |

Date |
Thu, 15 Nov 2012 11:21:57 +0000 |

Thanks Martin, it does run without any complaints. However, it does not provide the required. It compares each variable of next row as 'or' rather than 'and'. I wanted to compare two rows and if they are exactly the same then it should add money in the preceding row. Using this syntax it is adding money even only one variable is equal in value in the next row. Secondly, I wanted to assess which two rows are exactly the same using following command: foreach x of varlist v1-v10 { sort v1 v2,stable gen num=1 if `x'==`x'[_n+1] | `x'==`x'[_n-1] } this keep running the loop, error : num already defined. thanks again. m ________________________________________ From: owner-statalist@hsphsun2.harvard.edu [owner-statalist@hsphsun2.harvard.edu] on behalf of Maarten Buis [maartenlbuis@gmail.com] Sent: 15 November 2012 10:50 To: statalist@hsphsun2.harvard.edu Subject: Re: st: using loop for [_n+1] On Thu, Nov 15, 2012 at 11:37 AM, Dherani, Mukeshwrote: > I want to add money if the next row is exactly the same, however stata is coming up with errors when I used following syntax: > ("invalid syntax" <snip> > gen money=mone+mone[_n+1] if `x'=`x'[_n+1] The if condition should be: -if `x' == `x'[_n+1]- notice the == instead of = Hope this helps, Maarten --------------------------------- Maarten L. Buis WZB Reichpietschufer 50 10785 Berlin Germany http://www.maartenbuis.nl --------------------------------- * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/ * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/

**Follow-Ups**:**RE: st: using loop for [_n+1]***From:*"Sarah Edgington" <sedging@ucla.edu>

**Re: st: using loop for [_n+1]***From:*Nick Cox <njcoxstata@gmail.com>

**Re: st: using loop for [_n+1]***From:*Maarten Buis <maartenlbuis@gmail.com>

**References**:**st: using loop for [_n+1]***From:*"Dherani, Mukesh" <M.K.Dherani@liverpool.ac.uk>

**Re: st: using loop for [_n+1]***From:*Maarten Buis <maartenlbuis@gmail.com>

- Prev by Date:
**st: AW: AW: actually vs. reported dropped observations xtlogit** - Next by Date:
**Re: st: using loop for [_n+1]** - Previous by thread:
**Re: st: using loop for [_n+1]** - Next by thread:
**Re: st: using loop for [_n+1]** - Index(es):