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: Programming help


From   Sergiy Radyakin <[email protected]>
To   [email protected]
Subject   Re: st: Programming help
Date   Wed, 5 Jan 2011 18:58:37 -0500

Hi, Sergio,

I was thinking something along the lines below, but let me get to my
home pc and I can check more reliably.
(it removes those observations with flag==1, so what's left is
flag=0). The removed part can be restored easily.

Best Sergiy Radyakin



clear

input str2 pid  byte cid str11 from_dt str11 thru_dt
D1  1   "08 Nov 2008"          "13 Nov 2008"
D1  2   "13 Nov 2008"          "31 Dec 2008"
D1  3   "05 Dec 2008"          "06 Dec 2008"
D1  4   "07 Dec 2008"          "13 Dec 2008"
D1  5   "14 Dec 2008"          "20 Dec 2008"
D1  6   "21 Dec 2008"          "27 Dec 2008"
D1  7   "28 Dec 2008"          "31 Dec 2008"
D2  1   "14 Dec 2008"          "31 Dec 2008"
D2  2   "21 Dec 2008"          "27 Dec 2008"
D2  3   "31 Dec 2008"          "31 Dec 2008"
end

generate double from = date(from_dt, "DMY")
format from %td
generate double to = date(thru_dt,"DMY")
format to %td
list

drop from_dt thru_dt
list


local N1=_N+1

while (`=_N'!=`N1') {

bys pid (from): generate overlap=from<to[_n-1]
bys pid (from): replace overlap=0 if _n==1

drop if overlap
drop overlap

count
local N1=_N

}

// ----------- END OF FILE



On Wed, Jan 5, 2011 at 6:41 PM, Sergio Prada <[email protected]> wrote:
> Thanks Sergiy, please see answers to your questions below
>
> 1) what do you want your flag to be if there is a partial overlap?
> E.g. claim1 starts 10dec and lasts till 20dec, claim 2 starts 15 dec
> and lasts till 25dec.
>
> flag= 1
>
> 2)  is cid assigned chronologically? can there be duplicates (two
> claims with the same date).
>
> cid is not in the original data, I created cid using "sort from_dt
> thru_dt" and then "by pid: gen cid=_n"
>
> 3) if periods coincide how do you want to resolve the flag? (c1:
> 10th-20th and c2: 10th-20th,
> should the flag for c1 be 1 or for c2 be 1?)
>
> flag=1
>
> 4) in the example you illustrate the claims form chains, so that one
> claim starts next day after another ends. is that a specific pattern
> you are looking for?
>
> that is the typical pattern in these data, altough some claims start
> several days after the previous,
>
> Essentially what I am looking for is code that allow me to compare,
> within each pid, pairs of claims against certain condition.
> For instance, knowing start and thru date of cid1, compare that to the
> start and thru date of cid2, cid3, cid4, cid5, cid6 and cid7 and flag
> when both are the same. Then knowing start and thru date of cid2,
> compare that to the start and thru date of cid3, cid4, cid5, cid6 and
> cid7.
>
> Sergio
> *
> *   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/
>

*
*   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/


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