Dear Sir/Madam,

I am Masters student and working on Stata 14.2 obtained by my University.

I am attempting to calculate the measure the magnitude of antibiotic usage prior to a new incidence of a repeated illness. I ought to calculate two variables namely, the direct and indirect effects of using prescribed antibiotic on a set of illnesses.

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str23 ID str9 Illness float(YearofContracting DosageOfAntibiotic ClassofIllness)
"Patient 1" "Illness 1" 2010  37 1
"Patient 1" "Illness 1" 2008 100 1
"Patient 1" "Illness 1" 2011  49 1
"Patient 1" "Illness 2" 2001  15 1
"Patient 1" "Illness 2" 2012  60 1
"Patient 1" "Illness 3" 2006  26 2
"Patient 1" "Illness 4" 2018  80 2
"Patient 2" "Illness 1" 2013  89 1
"Patient 2" "Illness 1" 1999  15 1
"Patient 2" "Illness 2" 2016  90 1
"Patient 3" "Illness 1" 2001  18 1
"Patient 3" "Illness 4" 1987  10 3
"Patient 4" "Illness 7" 2002  30 3
"Patient 5" "Illness 8" 2004  60 4
end


I would like to explain with an example:

Direct effect
As per the Patient1 below, Illness 1 struck in year 2008, 20010 and 2011, hence, each successive occurrence of the same illness and its prescribed dosage has some impact on the patient's next occurrence of the same illness. By some logic, we believe that there is an impact of time gap signified by a constant multiple (let's call it gamma).

For Time lapse and constant multiple relationship, please refer the table below
Time lapse constant scale multiple (=gamma)
1 .1
2 .05
3 .007
4 .001
5 and above .0003
For Direct effect calculation
Incident1 of Illness 1: Direct effect (in year 2008)= 0
Incident2 of Illness 1: Direct effect (in 2010) = (corresponding gamma for time lapse between 2010-2008 )* DosageofAntibiotic (in 2008) * Count of same illness in year 2008
Incident3 of Illness 1: Direct effect (in 2011) = (corresponding gamma for time lapse between 2011 and 2008)* DosageofAntibiotic (in 2008)*Count of same illness in year 2008 + (corresponding gamma for time lapse between 2011-2010)* DosageofAntibiotic (in 2010)* Count of same illness in year 2010


Essentially:
[ATTACH=CONFIG]temp_16563_1577542093155_488[/ATTACH]
Indirect effect
For patient1, impact of illness 1 in the "year n" is dependent upon the prior incidents of illness 2 (because they are in same "Class of illness" - a variable in my data) that is incidents of illness 2 in year X (where X<n).
Time lapse constant scale multiple (=alpha)
1 .08
2 .021
3 .0078
4 .0004
5 and above .000065
Incident1 of Illness 1 (happens to be in year 2008): Indirect effect (of illness 2 which occured in year 2001)= (corresponding alpha for time lapse between 2008 and 2001 )* DosageofAntibiotic (in 2008) * Count of illness in same "Class of ui
Incident2 of Illness 1: Direct effect (in 2010) = (corresponding gamma for time lapse between 2010-2008 )* DosageofAntibiotic (in 2008) * Count of same illness in year 2008
Array
This is my first post in this community and I would appreciate all the help.

Regards,
Ram.