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

From |
John Antonakis <john.antonakis@unil.ch> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Re: Randomly selecting variables in panel, collapsing, and simulating |

Date |
Sat, 13 Jun 2009 19:21:47 +0200 |

Great. All works fine. A quick question on simulating now.

Best, J. ____________________________________________________ Prof. John Antonakis Associate Dean Faculty of Business and Economics University of Lausanne Internef #618 CH-1015 Lausanne-Dorigny Switzerland Tel ++41 (0)21 692-3438 Fax ++41 (0)21 692-3305 Faculty page: http://www.hec.unil.ch/people/jantonakis&cl=en Personal page: http://www.hec.unil.ch/jantonakis ____________________________________________________ On 13.06.2009 19:11, Martin Weiss wrote:

<>Last email was a little asinine... -simulate-´s default expression isonly _b, so you have to request _se...Also, I simply added additional clusters to the -input- statement...Everything should work as expected now. Check carefully for anynon-intuitive results, though...********** clear* input byte(i y x z n) 1 5 8 3 1 1 9 10 5 2 1 8 12 6 3 1 6 9 4 4 2 5 7 2 1 2 9 13 4 2 2 8 8 7 3 2 6 8 6 4 2 8 8 7 5 2 8 8 7 6 3 5 7 2 1 3 9 11 7 2 3 8 11 5 3 4 3 2 6 1 4 2 1 9 2 4 8 2 8 3 4 5 2 1 4 5 4 2 5 1 5 2 3 1 2 5 9 6 4 3 end capt prog drop sim /* Define the program */ prog sim vers 10.1 preserve gen random=runiform() sort i random by i: gen byte group=/* */cond(_n<=_N/2,1,2) drop random collapse (mean) y x z, /* */by(i group) /* get replacement as requested by John */ by i: replace y = y[1] by i: drop if _n==1 reg y x z restore end /* simulate */ simulate _b _se, reps(20)/* */ seed (123) : sim /* get t statistics and p values */ foreach v in x z { gen t_`v' = /* */_b_`v'/_se_`v' gen p_`v' =/* */ 2*(1-normal(abs(t_`v'))) } ********** HTH Martin _______________________ ----- Original Message ----- From: "Martin Weiss" <martin.weiss1@gmx.de> To: <statalist@hsphsun2.harvard.edu> Sent: Saturday, June 13, 2009 6:55 PMSubject: Re: st: Re: Randomly selecting variables in panel,collapsing, and simulating<>And here is how you would -simulate- the thing. With 3 observationsand 2 slopes plus constant, this model is not well identified, to putit mildly, so the standard errors are lacking and the last linescannot work... John, how do you intend to remedy the situation?********** clear* input byte(i y x z n) 1 5 8 3 1 1 9 10 5 2 1 8 12 6 3 1 6 9 4 4 2 5 7 2 1 2 9 13 4 2 2 8 8 7 3 2 6 8 6 4 2 8 8 7 5 2 8 8 7 6 3 5 7 2 1 3 9 11 7 2 3 8 11 5 3 end capt prog drop sim /* Define the program */ prog sim vers 10.1 preserve gen random=runiform() sort i random by i: gen byte group=/* */cond(_n<=_N/2,1,2) drop random collapse (mean) y x z, /* */by(i group) /* get replacement as requested by John */ by i: replace y = y[1] by i: drop if _n==1 reg y x z restore end /* simulate */ simulate, reps(20)/* */ seed (123) : sim /* get t statistics and p values */ foreach v in x z { gen t_`v' = /* */_b_`v'/_se_`v' gen p_`v' =/* */ 2*(1-normal(abs(t_`v'))) } ********** HTH Martin _______________________----- Original Message ----- From: "John Antonakis"<john.antonakis@unil.ch>To: <statalist@hsphsun2.harvard.edu> Sent: Saturday, June 13, 2009 6:24 PMSubject: Re: st: Re: Randomly selecting variables in panel,collapsing, and simulatingHi Martin:Thanks for the reply and the code! You are so helpful with everyoneand always seem to be able to find an elegant solution! As an aside,what is a nice resource to learn how to program nicely in Stata?I made a mistake in the 3), which you noticed.So, this was 2)--(I am only putting one space after each entry sothat the formatting doesn't get too messed up):i g y x z 1 1 6.5 10 4.5 1 2 7.5 9.5 4.5 2 1 7.3 9.3 4.3 2 2 7.3 8 6.7 3 1 5 7 2 3 2 8.5 11 6Now for 3), I want to put the data in such as way as to be able toregress the y of the first observation in each cluster on the x andz of the second observation in each clusteri y x z 1 6.5 9.5 4.5 2 7.3 8 6.7 3 5 11 6 Thank you very much for your help. Best, J. ____________________________________________________ Prof. John Antonakis Associate Dean Faculty of Business and Economics University of Lausanne Internef #618 CH-1015 Lausanne-Dorigny Switzerland Tel ++41 (0)21 692-3438 Fax ++41 (0)21 692-3305 Faculty page: http://www.hec.unil.ch/people/jantonakis&cl=en Personal page: http://www.hec.unil.ch/jantonakis ____________________________________________________ On 13.06.2009 18:06, Martin Weiss wrote:<>Here is the code for 1) and 2). I do not understand the intent innumber 3: If you really do want the first obs on y in each cluster,why does your example say "7.5" then? Should it not be 6.5?********** clear* input i y x z n 1 5 8 3 1 1 9 10 5 2 1 8 12 6 3 1 6 9 4 4 2 5 7 2 1 2 9 13 4 2 2 8 8 7 3 2 6 8 6 4 2 8 8 7 5 2 8 8 7 6 3 5 7 2 1 3 9 11 7 2 3 8 11 5 3 end compress list, noobs /* get groups */ gen random=runiform() sort i random by i: gen byte group=/* */cond(_n<=_N/2,1,2) l, noo sepby(i) drop random collapse (mean) y x z, /* */by(i group) l, noo sepby(i) ********** HTH Martin _______________________----- Original Message ----- From: "John Antonakis"<john.antonakis@unil.ch>To: <statalist@hsphsun2.harvard.edu> Sent: Saturday, June 13, 2009 3:19 PMSubject: st: Randomly selecting variables in panel, collapsing, andsimulatingHi:I want to do something that is quite straightforward, but don'tyet have the programming skills to do this, so I would appreciatesome help. Basically, I want to select randomly within clusters,then collapse, then estimate a regression model that I would liketo simulate. I would like to define it as an e-class program sothat I can easily incorporate a simulation in there.I have the following data structure (I have added a linein-between clusters to facilitate viewing):i y x z n 1 5 8 3 1 1 9 10 5 2 1 8 12 6 3 1 6 9 4 4 2 5 7 2 1 2 9 13 4 2 2 8 8 7 3 2 6 8 6 4 2 8 8 7 5 2 8 8 7 6 3 5 7 2 1 3 9 11 7 2 3 8 11 5 3Where y is the dependent variable, and x and z are covariates(note, I have more covariates, so I would like to use somethinggeneral that works even with more covariates), "i" is the panelidentifier and "n" is number of observations in each cluster. Notethat each cluster does not have the same number of observationsI would like to do the following:1) by cluster (i.e., within in each cluster), randomly split theobservations into two groups, with an equal amount of observations(if number of observations are even); if the number ofobservations are odd, then one of the group will have 1 moreobservation than the other. Thus, I would now have this:i y x z n g 1 8 12 6 3 1 1 5 8 3 1 1 1 6 9 4 4 2 1 9 10 5 2 2 2 9 13 4 2 1 2 5 7 2 1 1 2 8 8 7 3 1 2 8 8 7 5 2 2 6 8 6 4 2 2 8 8 7 6 2 3 5 7 2 1 1 3 8 11 5 3 2 3 9 11 7 2 2 2) collapse observations at the group level for each cluster to get: i g y x z 1 1 6.5 10 4.5 1 2 7.5 9.5 4.5 2 1 7.3 9.3 4.3 2 2 7.3 8 6.7 3 1 5 7 2 3 2 8.5 11 63) then I want to the data as below, so that I can regress the yof the first observation in each cluster to the x and z of thesecond observation in each clusteri y x z 1 7.5 9.5 4.5 2 7.3 8 6.7 3 8.5 11 2 4) once I have this I want to simulate it, using something like this: capture program drop sim version 10.1 program define sim, eclass[here is the code I would like to insert to make points 1-4 aboverun]simulate _b _se, reps(20) seed (123) : sim, foreach v in x z { gen t_`v' = _b_`v'/_se_`v' gen p_`v' = 2*(1-normal(abs(t_`v'))) Thank you. John. -- ____________________________________________________ Prof. John Antonakis Associate Dean Faculty of Business and Economics University of Lausanne Internef #618 CH-1015 Lausanne-Dorigny Switzerland Tel ++41 (0)21 692-3438 Fax ++41 (0)21 692-3305 Faculty page: http://www.hec.unil.ch/people/jantonakis&cl=en Personal page: http://www.hec.unil.ch/jantonakis ____________________________________________________ * * 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/* * 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**:**Re: st: Re: Randomly selecting variables in panel, collapsing, and simulating***From:*"Martin Weiss" <martin.weiss1@gmx.de>

**References**:**st: Randomly selecting variables in panel, collapsing, and simulating***From:*John Antonakis <john.antonakis@unil.ch>

**st: Re: Randomly selecting variables in panel, collapsing, and simulating***From:*"Martin Weiss" <martin.weiss1@gmx.de>

**Re: st: Re: Randomly selecting variables in panel, collapsing, and simulating***From:*John Antonakis <john.antonakis@unil.ch>

**Re: st: Re: Randomly selecting variables in panel, collapsing, and simulating***From:*"Martin Weiss" <martin.weiss1@gmx.de>

**Re: st: Re: Randomly selecting variables in panel, collapsing, and simulating***From:*"Martin Weiss" <martin.weiss1@gmx.de>

- Prev by Date:
**Re: st: Re: Randomly selecting variables in panel, collapsing, and simulating** - Next by Date:
**Re: st: Re: Randomly selecting variables in panel, collapsing, and simulating** - Previous by thread:
**Re: st: Re: Randomly selecting variables in panel, collapsing, and simulating** - Next by thread:
**Re: st: Re: Randomly selecting variables in panel, collapsing, and simulating** - Index(es):

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