Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

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

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

From   "Dherani, Mukesh" <>
To   "" <>
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. 

From: [] on behalf of Maarten Buis []
Sent: 15 November 2012 10:50
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"
> 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 L. Buis
Reichpietschufer 50
10785 Berlin
*   For searches and help try:
*   For searches and help try:

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