Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: The whole code of grid-search for "byable"


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: The whole code of grid-search for "byable"
Date   Thu, 24 Nov 2011 11:31:00 +0000

Adding -byable(recall)- is necessary but not sufficient to get this
working in the way you want. You are ignoring a crucial part of the
programming, involving -marksample touse-.

Nick

On Thu, Nov 24, 2011 at 11:21 AM, econqian222
<[email protected]> wrote:
> Hi, all
>     I encountered a problem in writing the code(grid-searching to obtain
> value of sigma) for each value of hs to get the corresponding value of
> sigma.  I made the code "byable" to run for each value of hs. However, once
> the program runs, and a sigma was obtained for its corresponding value of
> hs, all the values of sigma are given for the same value. Could anyone help
> me to check this problem?
>
> Many thanks in advance,
> Qian
>
>      The dataset goes like the following:
>
> hs y x1hat x2hat sigma
> 10290 736 283.731 141
> 10420 826 10.615 1.375
> 10511 276 78 2.687
> 10511 528 196.735 3.278
> 10511 818 148.753 11.0796
> 10511 251 4.861 .718
> 10519 276 6.189 .718
> 10519 276 9.396 .621
> 10519 404 7.355 .636
> 10591 682 10.8318 .812
> 10591 528 9.09482 .636
> 10591 276 8.49024 .417
>
> Program grid, byable(recall)
> "run the following grid-searching code"
> end
> by hs: grid
>
> The grid-searching code is listed as following:
> if sigma1 < 1 | sigma1 == . {
> local sigma1_hat = .
> local rho1_hat = .
> }
> local SigmaMin = 1.05
> local SigmaMax = 131.05
> local SigmaJump = 1.0
> local J1 = (`SigmaMax' - `SigmaMin')/`SigmaJump' + 2
> local J2 = 32
>
> sort product t
> mat uHat = J(`J1',`J2',.)
> local row = 2
>
> foreach s of numlist `SigmaMin'(`SigmaJump')`SigmaMax'{
> mat uHat[`row',1] = `s'
> local col = 2
> local RhoMax = (`s'-1)/`s'
> local RhoJump = `RhoMax' / (`J2' - 2)
> foreach r of numlist 0(`RhoJump')`RhoMax'{
> mat uHat[1,`col'] = `r'
> qui gen uTemp = y -((`r') / ((((`s')-1)^2) * (1-(`r')))) * x1hat-((2*(`r')
> -1) / (((`s')-1) * (1-(`r')))) * x2hat
> qui  gen sTemp = uTemp*uTemp*(1/period)
> qui summ sTemp, d
> mat uHat[`row',`col'] = r(sum)
> drop uTemp sTemp
> local col = `col' + 1
> }
> local row = `row' + 1
> }
> local MinU = uHat[2,2]
> local rho_hat = uHat[1,2]
> local sigma_hat = uHat[2,1]
> local row = 2
>
> foreach s of numlist `SigmaMin'(`SigmaJump')`SigmaMax'{
>  local col = 2
>
> foreach r of numlist 0(`RhoJump')`RhoMax'{
> if `MinU' > uHat[`row',`col'] {
> local MinU = uHat[`row',`col']
> local rho_grid_hat = uHat[1,`col']
> local sigma_grid_hat = uHat[`row',1]
> }
> local col = `col' + 1
> }
> local row = `row' + 1
> }
> foreach var in sigma rho {
> capture replace `var'1 = ``var'_grid_hat'
> local `var'1_hat = ``var'_grid_hat'
> }
>
>
>
>
> --
> View this message in context: http://statalist.1588530.n2.nabble.com/The-whole-code-of-grid-search-for-byable-tp7027780p7027780.html
> Sent from the Statalist mailing list archive at Nabble.com.
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index