Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

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


From   "Dherani, Mukesh" <[email protected]>
To   "[email protected]" <[email protected]>
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: [email protected] [[email protected]] on behalf of Maarten Buis [[email protected]]
Sent: 15 November 2012 10:50
To: [email protected]
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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index