Hi Statalists,

I have a problem that is more mathematical than Stata-related. I know this is a long shot, but I have to try.
  • I am calculating a score (HS) which runs on a scale from 0% to 100%.
  • HS should increase exponentially while state == 1.
  • HS should decrease exponentially while state == 0
  • HS should be 100% if state == 1, 91 t in a row. In other words if state == 1 for t1 to t91 (meaning the sum of state = 91), HS should be 100%.
I have the equation which works if state == 1 for t1 to t91, and I have the equation which decreases exponentially from 100% to 0% while state == 0 for t1 to t91.

Just for context, t = one day, and the 91 represents 3 months (365 / 12 * 3). The state refers to an occurrence that did (1) or did not (0) happen that day. If the occurrence happens 91 days in a row, HS must be 100%.

I don't know how to explain my problem better - which is probably why I haven't been successful finding a solution via Google.

Code if state == 1 for t1 to t91:
Code:
clear
insobs 91
egen t = seq()
gen state = 1
gen hs = (state*t^2)/(91^2)*100
twoway (line hs t)
Code if state == 0 for t1 to t91:
Code:
clear
insobs 91
egen t = seq()
gen state = 0
gen hs = (91^2-(-t-(1))^2)/(91^2)*100
twoway (line hs t)
In the end, the data, when plotted, should look something like this, assuming a period where state ==1, followed by a period where state ==0, followed by a period where state == 1 again:
Array
Thank you so much in advance.