Announcement

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

  • Karol Podolski
    started a topic Bootstrap for regression parametrs

    Bootstrap for regression parametrs

    preserve
    local var1 = "price"
    local var2 = "weight"
    local n=r(N)
    local B=1000
    local alfa = 0.05 //b to liczba próbek
    forvalues i=1/`B'{
    generate sampl`i'=`var1'[ceil(`n'*runiform())]
    generate sampl1`i'=`var2'[ceil(`n'*runiform())]
    reg var1 var 2
    }

  • Karol Podolski
    replied
    Ok. I understand. Can you give me answer how i can save my single observation in matrix ? I try this way but this is bad why.
    Code:
    preserve
    local zmienna = "price"
    quietly summ `zmienna'
    local n=r(N)
    local B=1000
    local alfa = 0.05 //b to liczba próbek
    forvalues i=1/`B'{
    generate proba`i'=`zmienna'[ceil(`n'*runiform())]
    quietly summ proba`i'
    matix A[1,i]=proba`i'
    }

    Leave a comment:


  • Maarten Buis
    replied
    We are obviously not going to do your homework for you. So I can only give you some hints. You could look at the series of blog posts starting here: https://blog.stata.com/2012/07/18/us...rators-part-1/

    Leave a comment:


  • Karol Podolski
    replied
    Because its my homework :/

    Leave a comment:


  • Maarten Buis
    replied
    To copy Weiwen: Why? We really need to know why. We want to help you, but you need to help us help you. I think you wanted to answer my questions in #9, but there you only gave us what you want but not why you want it.

    Leave a comment:


  • Weiwen Ng
    replied
    Originally posted by Karol Podolski View Post
    I need to progam the bootstrap by hand and make it most efficient way to minimalize standard errors but bootstrap should be by hand. I want to do the sampling by hand. ...
    Again, why? You are not trying to estimate some strange statistic where we don't know the theoretical variance of its estimator. Also, you still haven't explained why you need to do the bootstrap by hand, instead of letting Stata do it for you from your existing data.

    Leave a comment:


  • Karol Podolski
    replied
    I need to progam the bootstrap by hand and make it most efficient way to minimalize standard errors but bootstrap should be by hand. I want to do the sampling by hand .For example (for mean value)
    preserve
    [code]
    local zmienna = "price"
    quietly summ `zmienna'
    local n=r(N)
    local B=1000
    local alfa = 0.05 //b to liczba próbek
    forvalues i=1/`B'{
    generate proba`i'=`zmienna'[ceil(`n'*runiform())]
    quietly summ proba`i'
    }
    if `B'>`n'{
    set obs `B'
    generate srednie =.

    forvalues i=1/`B'{
    quietly summ proba`i' //
    quietly replace srednie=r(mean) in `i'
    }
    sort srednie
    local lb=srednie[ceil((`alfa'/2)*`B')]
    di `lb'
    local ub=srednie[ceil((1-(`alfa'/2))*`B')]
    di `ub'
    display "przedział ufnosci obliczony metodą bootstrap dla `B' iteracji"
    display "`lb' `ub'"
    restore
    [code]

    Bootstrap doesn't must be perfect, i need program which reminds bootstrap and minimalize standards errors for regression.

    Leave a comment:


  • Maarten Buis
    replied
    Why do you want to do that? You may think we only need to know what you want, but your question is unclear without knowing the why. Right now, we could give you very different answers, which will help you attain different goals. Do you want to program the bootstrap by hand (maybe for educational purposes) or do you want the most efficient way to get the bootstrap standard errors/confidence intervals?

    If you want the latter, then just do: reg price weight, vce(bootstrap, reps(20000))

    If you want the former, then you need to be even more precise about what you want to do (and what not). Just give us a step by step guide of what you want to do. It is not clear to me from your question how far you want to go. For example, are you happy with using a Stata program to do the sampling for you, or do you want to program that yourself as well?

    Leave a comment:


  • Weiwen Ng
    replied
    Originally posted by Karol Podolski View Post

    Thank you very much for reply, but i need to generate new 1000 sample, make regression to 1000 sample, save 2 regression parametrs for each sample and next make bootstrap i think its other case but probably i be wrong because my knowladge about stata is under amator and i cant read syntax on this program. Say me please if this the same.
    Karol,

    I don't understand what you are asking. Most of the time, we would use bootstrap to estimate the variance of some quantity (e.g. a regression parameter) after a regression. Generate 1000 samples sounds a lot like the bootstrapping process itself. Can you ask someone whose English is better to translate?

    Leave a comment:


  • Karol Podolski
    replied
    Originally posted by Joro Kolev View Post
    Stata has convenient command that bootstraps for you. What you want can be achieved automatically by

    Code:
    . sysuse auto, clear
    (1978 Automobile Data)
    
    . bootstrap _b[weight], reps(1000) saving(mybootsample, replace) nodots: reg price weight
    
    Linear regression Number of obs = 74
    Replications = 1,000
    
    command: regress price weight
    _bs_1: _b[weight]
    
    ------------------------------------------------------------------------------
    | Observed Bootstrap Normal-based
    | Coef. Std. Err. z P>|z| [95% Conf. Interval]
    -------------+----------------------------------------------------------------
    _bs_1 | 2.044063 .3982494 5.13 0.000 1.263508 2.824617
    ------------------------------------------------------------------------------
    
    
    . use mybootsample
    (bootstrap: regress)
    
    . summ
    
    Variable | Obs Mean Std. Dev. Min Max
    -------------+---------------------------------------------------------
    _bs_1 | 1,000 2.035768 .3982494 .3991753 3.156375
    Thank you very much for reply, but i need to generate new 1000 sample, make regression to 1000 sample, save 2 regression parametrs for each sample and next make bootstrap i think its other case but probably i be wrong because my knowladge about stata is under amator and i cant read syntax on this program. Say me please if this the same.

    Leave a comment:


  • Carlo Lazzaro
    replied
    Karol:
    the -bootstrap- entry in Stata .pdf manual includes interesting examples that are worth reading.

    Leave a comment:


  • Joro Kolev
    replied
    Stata has convenient command that bootstraps for you. What you want can be achieved automatically by

    Code:
    . sysuse auto, clear
    (1978 Automobile Data)
    
    . bootstrap _b[weight], reps(1000) saving(mybootsample, replace) nodots: reg price weight
    
    Linear regression                               Number of obs     =         74
                                                    Replications      =      1,000
    
          command:  regress price weight
            _bs_1:  _b[weight]
    
    ------------------------------------------------------------------------------
                 |   Observed   Bootstrap                         Normal-based
                 |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
           _bs_1 |   2.044063   .3982494     5.13   0.000     1.263508    2.824617
    ------------------------------------------------------------------------------
    
    
    . use mybootsample
    (bootstrap: regress)
    
    . summ
    
        Variable |        Obs        Mean    Std. Dev.       Min        Max
    -------------+---------------------------------------------------------
           _bs_1 |      1,000    2.035768    .3982494   .3991753   3.156375

    Leave a comment:


  • Karol Podolski
    replied
    Hi everyone. I need to make bootstrap for regression paramatr for price and weight in new sample from general population, but i don't know how to make regression in new sample.
    I want to make 1000 new samples, make regression price weight, save parametrs of regression for each sample and according to parameters make bootstrap.

    Leave a comment:


  • Marcos Almeida
    replied
    Welcome to the Stata Forum/Statalist.

    Please read the FAQ. There you will find advice on how to post an insightful thread.

    You might well read about the best way to share command/data/output, which are: 1) under code delimiters; 2) with - dataex - command, if your version is new, or the SSC dataex otherwise.

    To end, I can see you have written a code. That is all.

    Your post seems to lack communication skills, hence I fail to understood what kind of help you wish from the Stata community.

    Leave a comment:

Working...
X