Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Francesco <cariboupad@gmx.fr> |
To | statalist@hsphsun2.harvard.edu |
Subject | st: Nearest value in a not xtset-able panel dataset |
Date | Wed, 28 Mar 2012 19:12:15 +0200 |
Dear Statalist, I have a simple algorithmic problem that I was unable to solve so far... Let us assume that I have the following dataset, where special_date identifies ... a special date ;-) ID DATE SPECIAL_DATE DIFFERENCE Jack 1 0 missing Jack 4 0 -1 Jack 4 0 -1 Jack 5 1 0 Jack 7 0 missing Jack 9 0 missing Jack 10 0 missing Jack 11 0 -1 Jack 12 1 0 Jack 13 0 +1 Jack 13 0 +1 Jack 17 0 missing My question is : How could I obtain the variable DIFFERENCE that gives me the difference between the current observation's date and the nearest special date if this distance is less than a threshold N (N=1 in the example)? In any case N is much smaller than the periodicity of special date. For example N could be 10 days and Special date could occur only one time each quarter. Could you please help me (if possible)? Many, many thanks in advance, Best, * * 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/