Hi, I am recently writing a function in Mata.
In the function, I have to first declare a set of variables.
However, the problem is that the number of variables depends on the data I will use.
For example, if we use an imaginary data, say dt1, then we have to write
But, if we use another imaginary data set, say dt2, then we have to specify
In addition, we cannot predict what data will be used between dt1 and dt2, but we can know whether dt1 is being used or dt2 is being used before the function is executed.
That is, we can add a diagnostic tool, for instance,
In this case, how can I declare the variable flexibly?
In the function, I have to first declare a set of variables.
However, the problem is that the number of variables depends on the data I will use.
For example, if we use an imaginary data, say dt1, then we have to write
Code:
: void my_fun() { real colvector var1, var2, var3 . . . }
Code:
: void my_fun() { real colvector var1, var2, var3, var4, var5, var6, var7 . . . }
That is, we can add a diagnostic tool, for instance,
Code:
if (max(my_var) == 3) { printf("this is dt1") } else if (max(my_var) == 7) { printf("this is dt2") }
Comment