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: Comparing two data set
From
Nick Cox <[email protected]>
To
[email protected]
Subject
Re: st: Comparing two data set
Date
Wed, 2 Mar 2011 09:52:43 +0000
This won't work as you intend.
1. The -foreach- loop is intended to be a loop over variables, but the
syntax is wrong. That is fixable.
2. More importantly, you want to compare pairs of observations, but
your code just looks at differences between variables within the same
observation.
The underlying idea is good, but is already implemented, for example
in -duplicates-. No loops are needed.
Nick
On Wed, Mar 2, 2011 at 9:15 AM, Robert L. Hellpap
<[email protected]> wrote:
> How about appending the data and using loops to create a difference
> indication variable? If the new appended variables have the same name as the
> old ones plus for example a 1 should it be possible to do it like :
>
> foreach x in firstoldvar-lastoldvar{
> gen `x'dif=0
> forvalues i=1(1)1000{
> replace `x'dif=1 if `x'!=`x'1 & id==`i'
> }
> tab `x'1 id if `x'==1
> }
>
> Now for each individual both datasets are compared by their value, if they
> are not equal the vardif-dummy should be 1 and after the replace line the
> id's for which the value differs will be displayed. Not sure if this works
> without problems, would be interested about comments. (Even though I think
> the idea of merging is very smart und uncomplicated)
> *
*
* 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/