I don't see that you need a function here.
The set of variables with "clli" as part of
their names is given by the wildcard *clli*
and so can be put into a macro by
unab clli : *clli*
Presumably you know what variables appear
on the RHS of your regression and can manufacture
a local macro containing them, say rhs.
The intersection is then
local cllirhs : list clli & rhs
and you can cycle over these with
foreach v of local cllirhs {
... = ... + _b[`v']
}
Assuming that by Fourrier you mean Fourier, I don't see why
handling a set of Fourier terms need be messy. The utility
-fourier- from -circular- on SSC provides one way of getting
a bunch of them.
Alternatively, in one recent program I needed to generate a bunch
of them on the fly. Here is the code generalised mildly:
// regression in terms of sin j theta, cos j theta
local sc
local terms = <plug in your own>
forval j = 1/`terms' {
tempvar S C
gen `S' = sin(`j' * `theta')
gen `C' = cos(`j' * `theta')
local sc `sc' `S' `C'
}
// regression will fail if data points too few
// or response missing
// assumes a `touse' marking observations to be used
capture regress <response to be plugged in> `sc' if `touse'
if _rc gen `sm' = . if `touse'
else predict `sm' if `touse'
drop `sc'
On the other hand, quite what a "Flexible" Fourier analysis
is I don't know.
Nick
[email protected]
Dev Vencappa
> I have the following problem and would be grateful if you
> could provide some help:
>
> Suppose I have a regression equation with lntoen as my
> dependent variable and a lot of right hand side variables
> called lncllisqr lncllica lncllite lncaclli (and there are
> more variables like these which contain the word "clli" in
> their name as well as other variables named differently).
> After estimation, I am trying to add the coefficients of all
> variables in an estimation that have "clli" in their names.
> While I can do this manually by using _b[variablename], I am
> faced with a problem as I am estimating a Flexible Fourrier
> function, which tends to be very messy in terms of the
> addition of trigonometric terms.
>
> I am trying to differentiate lntoen with respect to all
> variables that contain "clli" in their names. I am trying to
> automate this process by asking stata to add the coefficients
> of all variables that contain "clli" in their names.
>
> Does anybody know if there is an equivalent to one of the
> list of string functions (such as e.g. substr) that can allow
> me to write some condition to check if the variable contains
> the characters "clli" in its name and then add their
> coefficients please?
>
> Apologies if a similar posting has been up on the list before
> and escaped my attention.
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/