Dear all,
I wonder if anyone has a better solution to the following problem.
Say that I'm interested in estimating K linear regressions simultaneously using -ml- approach.
where K is variable, But I know it beforehand, But I do not want to write the program that defines the Loglikehood for every case (every k in K)
So I came up with this solution:
My program will be:


Code:
program myols2
args lnf $args
qui {
    replace `lnf'=0
    forvalues i = 1/$k {
        replace `lnf'=`lnf' + log(normalden(${ML_y`i'},`xb`i'',exp(`lns`i'')))
    }
}
end
And to estimate a model using -ml- I could use this code:

Code:
global k 2
global args xb1 lns1 xb2 lns2
ml model lf myols2 ( price = foreign weight length) /lns1 (mpg =foreign weight)  /lns2
ml maximize

global k 3
global args xb1 lns1 xb2 lns2 xb3 lns3
ml model lf myols2 ( price = foreign weight length) /lns1 (mpg =foreign weight)  /lns2 (displ = foreign weight) /lns3
ml maximize
In other words, Im passing the arguments of the Number of equations (K), and the different names of elements in the equation (xb`i' and lns`i') manually using a "global".

Since globals can some times be problematic (as they could create conflicts that could be undetectable when using multiple programs), I wonder if anyone has an alternative solution to modify the number of "arguments
my "myols2" programs should accept, or the number of equations to be estimated.

Thank you
Fernando