I have the following dataset. I want to keep d=1 for the first observation within 30-day moving window, and replace d=0 if the observation is the 2nd and nth observations within the window.
My difficulty is , this is not a moving window. For example, for the first 30-day window, it begins from 02jan1990 to 1Feb1990. The 2nd 30-day window begins from 2Feb1990 instead of 03Jan1990. Is there any way to do it? Or is there any trick for this?

My gut feeling is, to play around with rangestat can solve the question, but I have spent 3 hour and could not think of a solution.

Any help is greatly appreciated.

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input double permno long date float d
10001 10959 1
10001 10965 1
10001 10966 1
10001 10967 1
10001 10968 1
10001 10969 1
10001 10973 1
10001 10974 1
10001 11021 1
10001 11023 1
10001 11024 1
10001 11029 1
10001 11035 1
10001 11037 1
10001 11042 1
10001 11043 1
10001 11044 1
10001 11120 1
10001 11128 1
10001 11130 1
10001 11140 1
10001 11143 1
10001 11144 1
10001 11148 1
10001 11149 1
10001 11150 1
10001 11151 1
10001 11154 1
10001 11164 1
10001 11168 1
10001 11170 1
10001 11175 1
10001 11176 1
10001 11177 1
10001 11183 1
10001 11497 1
10001 11501 1
10001 11505 1
10001 11506 1
10001 11513 1
10001 11514 1
10001 11518 1
10001 11519 1
10001 11527 1
10001 11528 1
10001 11532 1
10001 11533 1
10001 11535 1
10001 11536 1
10001 11542 1
10001 11543 1
10001 11546 1
10001 11547 1
10001 11548 1
10001 11549 1
10001 11550 1
10001 11554 1
10001 11555 1
10001 11556 1
10001 11557 1
end
format %d date