'How can I simplify the formula in R?

I want to estimate a set formulas in R by systemfit,for each formula,it's mathmatic expression can be written as https://www.mathcha.io/editor/VQKXXuLvCjWClxjyy4Ie0xBKOC1eN3lgCMMXdgG

In stata ,I can handle it by

gen double `lnap' = `a0' + `a1'*`lnp1' + `a2'*`lnp2' + `a3'*`lnp3' + `a4'*`lnp4' + `a5'*`lnp5' + `a6'*`lnp6'
forvalues i = 1/6 {
    forvalues j = 1/6 {
        replace `lnap' = `lnpindex' + 0.5*`g`i'`j''*`lnp`i''*`lnp`j''
        }
    }

gen double `bp' = 0
forvalues i = 1/6 {
    replace `bp' = `bofp' + `lnp`i''*`b`i''
}

replace `w1' = (`a1' + `g11'*`lnp1' + `g12'*`lnp2' + `g13'*`lnp3' + `g14'*`lnp4' + `g15'*`lnp5' + `g16'*`lnp6' + ///
`b1'*(`lnm' - `lnap') + `l1'/`bp'*(`lnm' - `lnap')^2 + `z1'*`eta11' + `z2'*`eta21' + `z3'*`eta31' + `z4'*`eta41'+ `z5'*`eta51'

I have read manuel for formula,it seems that the only way is to simplify this equation.I wonder if you can tell me how to write this complex equation to formula in R? Many thanks!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source