Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Boost up iteration speed.

    Hello, I want to make simple parametric non-linear least square using nl function.

    The problem is I want to put individual fixed effect with 1130 dummy variable.

    I want to allow individual heterogeneity on the intercept.

    Here is my current code, however, it will take more than 10 hours.

    Is there any method I can run the code faster?

    I don't have an interest in the specific value of the individual dummy. I just want to control them.


    program nldtshare
    version 14.0
    syntax varlist(min=5 max=5) [aw fw iw] if, at(name)
    local dt_share: word 1 of `varlist'
    local distance_pre: word 2 of `varlist'
    local t: word 3 of `varlist'
    local treatment: word 4 of `varlist'
    local txtreatment: word 5 of `varlist'


    // Retrieve parameters out of at matrix
    tempname d0 d1 d2 d3 g0 g1 g2 g3
    scalar `d0' = `at'[1,1]
    scalar `d1' = `at'[1,2]
    scalar `d2' = `at'[1,3]
    scalar `d3' = `at'[1,4]
    scalar `g0' = `at'[1,5]
    scalar `g1' = `at'[1,6]
    scalar `g2' = `at'[1,7]
    scalar `g3' = `at'[1,8]



    tempvar dterm gterm indv
    generate double `dterm' = `d0'+`d1'*`t'+`d2'*`treatment'+`d3'*`txtreatment' `if'
    generate double `gterm' = `g0'+`g1'*`t'+`g2'*`treatment'+`g3'*`txtreatment' `if'

    replace `dt_share' = `dterm'*(`distance_pre')^`gterm' `if'
    local atcnt=9
    forval i=1/1130{
    replace `dt_share'=`dt_share'+`at'[1,`atcnt']*(id==`i') `if'
    local `++atcnt'

    }
    end

  • #2
    I want to add that STATA only uses 12% of my CPU.

    Comment


    • #3
      I don't see your call to nl. Would be good to see an example of the dataset and the actual estimation. Stata might get stuck somewhere. Without more details, it is hard to help you further.

      Comment


      • #4
        It is possible Stata only uses 12% of your CPU because (perhaps) you have 8 processors - nl is probably not paralleled for your model. 1100 parameters is likely to take some time - depends on the sample size also. But, Sven-Kristjan's question also deserves consideration - is Stata hanging with the same likelihood function value and parameters or is it continuing to make progress over the 10 hours? If it is just taking time because it is so big, you might speed things along by giving Stata better starting values.

        Comment

        Working...
        X