I have a panel containing daily data which are not all continuous. Within an ID, if those dates are continuous or the gap between two dates is less than 30 days, they can be defined as one group. I would like to create a variable to distinguish these groups, for example, a variable equals to 1 for the first group of continuous date, 2 for the second group of continuous dates, etc.

In short, the goal is to create "indi3"
I was thinking create "indi1" to identify the occurrence of first not continuous date, "indi2" defined as following.

gen indi2=0
bysort id: replace indi2=indi1 if _n==1
bysort id: replace indi2=indi2[_n]+indi1[_n-1] if indi2!=1

The goal can be achieved if the last row of command can be looped, but I am not sure how to do it.
Otherwise, I would like to know is there any other method to achieve this goal?

Thank you
id date indi1 indi2 indi3 (this is the goal)
1 24mar2018 1 1 1
1 25mar2018 1 1
1 26mar2018 1
1 27mar2018 1
1 28mar2018 1
1 29mar2018 1
1 20sep2019 1 2
1 21sep2019 1 2
1 22sep2019 2
1 23sep2019 2
1 24sep2019 2
1 25sep2019 2
1 26sep2019 2
1 27sep2019 2
2 04dec2018 1 1 1
2 05dec2018 1 1
2 06dec2018 1
2 07dec2018 1
2 09mar2019 1 2
2 10mar2019 1 2
2 11mar2019 2
2 12mar2019 2
2 29jun2019 1 3
2 30jun2019 1 3
2 01jul2019 3
2 02jul2019 3
2 09oct2019 1 4
2 10oct2019 1 4
2 11oct2019 4
2 12oct2019 4
2 13oct2019 4
2 14oct2019 4
2 15oct2019 4