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

From |
"Martin Weiss" <martin.weiss1@gmx.de> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
st: AW: AW: Cannot initialize matrix to store summed coefficient estimates |

Date |
Thu, 24 Sep 2009 16:42:06 +0200 |

<> You could even shorten the lines ************* gen byte sample= if runiform()<0.7 reg y x* if sample ************* to - reg y x* if runiform()<0.7- as Stata will evaluate the qualifier on the fly... HTH Martin -----Ursprüngliche Nachricht----- Von: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Martin Weiss Gesendet: Donnerstag, 24. September 2009 16:38 An: statalist@hsphsun2.harvard.edu Betreff: st: AW: Cannot initialize matrix to store summed coefficient estimates <> Here is a way to make this work for a 70% random sample... ************* //drop it beforehand capt prog drop sim drop _all set obs 10000 gen x1= rnormal() gen x2= rnormal() //DGP gen y= 1+2*x1+4*x2+rnormal() //define the program program define sim version 10.1 preserve //70% sample gen byte sample=runiform()<0.7 reg y x* if sample restore end //simulate it! simulate _b _se, /* */ reps(100): sim renpfix _b_ pointest_ renpfix _se_ standerror_ list, noobs h(40) ************* HTH Martin -----Ursprüngliche Nachricht----- Von: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Diederik van Liere Gesendet: Donnerstag, 24. September 2009 16:23 An: statalist@hsphsun2.harvard.edu Betreff: st: Cannot initialize matrix to store summed coefficient estimates Dear Statalist members, I am trying to write a simple macro that takes a random sub sample of my dataset, run my regression and aggregates the e(B) matrices in a new matrix so I can calculate the average coefficient estimate and the average standard error. However, I am a bit stuck with initializing the matrix that will contain the summed coefficients and summed standard errors. What I have been trying to do looks like this: local define matrix X foreach v of varlist 'varlist' { //create 1 x k matrix with initial values 0.0 matrix X[1, "`v'"]= 0.0 } forvalues i =1/n { preserve generate x =runiform() //some more code to create random sample regress varlist matrix y = e(b) foreach b of e(b) { matrix X[1,`b'] = matrix X[1,`b'] + _b["`b'"] } matrix list X restore } Unfortunately, I don't know how to fix the error that is thrown on row 3 (matrix X[1, "`v'"] = 0.0 Stata exits with a type mismatch error and I have tried a whole range of alternatives but so far nothing works.... I would appreciate any suggestions to get this macro working and I am sure it's quite simple but I have been staring at this for too long :( Best regards, Diederik van Liere * * 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/ * * 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/

**Follow-Ups**:**st: graphs and version control***From:*"Isabelle Deltour" <deltour@cancer.dk>

**References**:**st: Cannot initialize matrix to store summed coefficient estimates***From:*Diederik van Liere <Diederik.vanLiere@Rotman.Utoronto.Ca>

**st: AW: Cannot initialize matrix to store summed coefficient estimates***From:*"Martin Weiss" <martin.weiss1@gmx.de>

- Prev by Date:
**st: AW: Cannot initialize matrix to store summed coefficient estimates** - Next by Date:
**RE: st: RE: AW: problem with destring** - Previous by thread:
**st: AW: Cannot initialize matrix to store summed coefficient estimates** - Next by thread:
**st: graphs and version control** - Index(es):

© Copyright 1996–2014 StataCorp LP | Terms of use | Privacy | Contact us | What's new | Site index |