hi i have trouble creating a function program evaluator for a non linear regression
program nlwind
version 12
syntax varlist(min=1 max=1500) if, at(name)
*dependent variable is the first one in my variable list
local depend : word 1 of `varlist'
*as I have to work on my variable in pairs I count how many pairs I have in addition to my dependent variable
local count : word count `varlist'
replace count=(count-1)/2
// Retrieve parameters out of at
*those are two parameters that are the same across pairs of variables
tempname sigma0 sigma1
scalar `sigma0' = `at'[1,1]
scalar `sigma1' = `at'[1,2]
//loop to create all the terms
*I need to generate terms using pairs of variables (630pairs) so I use a loop
forvalues i=1/`count' {
// local variables
*extract the code of the pair, the name of "even" variables is of the type pinstallCODE where CODE is a 4 or 5 digit code
local pinst : word 2*`i' of `varlist'
local ins= substr("`pinst'", 9, .)
*create the index that will let me access both variables of pair `i'
local j=2*`i'
local k=2*`i'-1
*locals of those variables
local pinst`ins' : word `j' of `varlist'
local wprev`ins' : word `k' of `varlist'
// Retrieve parameters from the loop out of at
*define a pair specific parameter, coded with the 4- or 5- digits extracted above and stored in local `ins'
tempname multi`ins'
scalar `multi`ins'' = `at'[1,2+i]
// Some temporary variables
*generate pair-specific terms, which have to be summed
tempvar prodvent`ins' sumterms
generate double `prodvent`ins''=pinst`ins'*(14/(14 + exp(-1*`sigma0' *(`multi`ins''*wprev`ins'- `sigma1'))))*(`multi`ins''*wprev`ins'<25) `if'
capture gen double `sumterms'=`prodvent`ins'' `if'
capture replace `sumterms'=`sumterms'+`prodvent`ins'' `if'
}
//Fill dependant variable
*the regression takes place on the sum of the terms generated in the loop, the sum is stored in `sumterms'
replace `depend'=`sumterms' `if'
end
program nlwind
version 12
syntax varlist(min=1 max=1500) if, at(name)
*dependent variable is the first one in my variable list
local depend : word 1 of `varlist'
*as I have to work on my variable in pairs I count how many pairs I have in addition to my dependent variable
local count : word count `varlist'
replace count=(count-1)/2
// Retrieve parameters out of at
*those are two parameters that are the same across pairs of variables
tempname sigma0 sigma1
scalar `sigma0' = `at'[1,1]
scalar `sigma1' = `at'[1,2]
//loop to create all the terms
*I need to generate terms using pairs of variables (630pairs) so I use a loop
forvalues i=1/`count' {
// local variables
*extract the code of the pair, the name of "even" variables is of the type pinstallCODE where CODE is a 4 or 5 digit code
local pinst : word 2*`i' of `varlist'
local ins= substr("`pinst'", 9, .)
*create the index that will let me access both variables of pair `i'
local j=2*`i'
local k=2*`i'-1
*locals of those variables
local pinst`ins' : word `j' of `varlist'
local wprev`ins' : word `k' of `varlist'
// Retrieve parameters from the loop out of at
*define a pair specific parameter, coded with the 4- or 5- digits extracted above and stored in local `ins'
tempname multi`ins'
scalar `multi`ins'' = `at'[1,2+i]
// Some temporary variables
*generate pair-specific terms, which have to be summed
tempvar prodvent`ins' sumterms
generate double `prodvent`ins''=pinst`ins'*(14/(14 + exp(-1*`sigma0' *(`multi`ins''*wprev`ins'- `sigma1'))))*(`multi`ins''*wprev`ins'<25) `if'
capture gen double `sumterms'=`prodvent`ins'' `if'
capture replace `sumterms'=`sumterms'+`prodvent`ins'' `if'
}
//Fill dependant variable
*the regression takes place on the sum of the terms generated in the loop, the sum is stored in `sumterms'
replace `depend'=`sumterms' `if'
end
Comment