I am trying to fit a Poisson regression model using my own likelihood function. I have seen the basic example of how I would do it but the thing is that my function has several if statements that makes it really complicated. I managed to write the code for this in SAS but I can't seem to get the whole Idea to STATA.
If SMD650 is not 20 and not 30 the log likelihood function should be something like what is written on line 14 (Normal likelihood function for a poisson distribution)

This is coded in line 15 to 22

The likelihood function therefore checks the value of SMD650 first, then depending on the value it does the summation appropriately. there after the likelihood function is then applied to the model with Age as the independent variable.
below is the SAS code.....how can I come up with a STATA code?
If SMD650 is not 20 and not 30 the log likelihood function should be something like what is written on line 14 (Normal likelihood function for a poisson distribution)
This is coded in line 15 to 22
The likelihood function therefore checks the value of SMD650 first, then depending on the value it does the summation appropriately. there after the likelihood function is then applied to the model with Age as the independent variable.
below is the SAS code.....how can I come up with a STATA code?
- proc nlmixed data = Work.final ;
- array v[10];
- array n[10];
- do i = 1 to 10;
- v[i] = i + 4;
- n[i] = i + 14;
- end;
- parms b0=0 b1=0;
- mu = exp(b0 + b1*Age);
- if SMD650 ~= 10 and SMD650 ~=20 then
- ll = log(((mu**SMD650)*exp(-mu))/gamma(SMD650+1));
- else if SMD650= 20 then do;
- p = 0;
- do i = 1 to 6;
- p = p + ((n[i]-15)/5)*((mu**n[i])*exp(-mu))/gamma(n[i]+1);
- end;
- do i = 7 to 10;
- p = p + ((24-n[i])/4)*((mu**n[i])*exp(-mu))/gamma(n[i]+1);
- end;
- ll=log(p);
- end;
- else do;
- sum = 0;
- do i = 1 to 6;
- sum = sum + ((v[i]-5)/5)*((mu**v[i])*exp(-mu))/gamma(v[i]+1);
- end;
- do i = 7 to 10;
- sum = sum + ((14-v[i])/4)*((mu**v[i])*exp(-mu))/gamma(v[i]+1);
- end;
- ll=log(sum);
- end;
- model SMD650 ~ general(ll);
- run;