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

Re: st: Can -bootstrap- handle vectors

 From Matthew White <[email protected]> To [email protected] Subject Re: st: Can -bootstrap- handle vectors Date Sat, 13 Aug 2011 12:12:48 +0300

```I don't know of a way to use Mata to put numeric values in a local.
st_local only works with string values, I think. But you could return
each element of a Mata vector to separate Stata scalars. Say X is a
Mata column vector:
mata: st_numscalar("r(rows)", rows(X))
forvalues row = 1/`r(rows)' {
mata: st_numscalar("r(v`row')", X[`row', 1])
}

Hope that helps!

On Sat, Aug 13, 2011 at 11:40 AM, Alex Olssen <[email protected]> wrote:
> Hi Statalisters,
>
> It seems to me that -bootstrap- cannot handle vectors?  Is this
> correct?  If so, does anyone know if there is a way to use a loop to
> send each element of a Mata vector to a separate Stata local so I can
> bootstrap the vector element by element?
>
> Sample code is below.  All help greatly appreciated!
>
> ************************************************************
> capture program drop my_vector
> program define my_vector, rclass
>        syntax varlist
>        mata: m_my_vector("`varlist'")
>        return list
> end
>
> capture mata mata drop m_my_vector()
> mata:
> void m_my_vector(string scalar varlist)
> {
>        real matrix data, data_cov
>        st_view(data, ., varlist)
>        data_cov = variance(data)
>        st_matrix("r(v1)", data_cov[., 1])
>        st_numscalar("r(v11)", data_cov[1, 1])
> }
> end
>
> sysuse auto, clear
> my_vector price length weight
> di r(v11)
> matrix list r(v1)
>
> bootstrap r(v11), reps(200) seed(13082011): my_vector price length weight
> bootstrap r(v1), reps(200) seed(13082011): my_vector price length weight
> ************************************************************
>
> Cheers,
> Alex Olssen
> *
> *   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/
>

--
Matthew White
Evaluation Coordinator
Urban Micro-Insurance Project
Innovations for Poverty Action

+254 (0)701 025 276
[email protected]

*
*   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/
```