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: Re: Simulating static panels


From   Melvyn Weeks <[email protected]>
To   [email protected]
Subject   Re: st: Re: Simulating static panels
Date   Tue, 27 Nov 2012 13:16:55 +0000

Many thanks Maarten

Melvyn

On 27/11/2012 11:02, Maarten Buis wrote:
On Tue, Nov 27, 2012 at 11:42 AM, Melvyn Weeks wrote:
can anyone point me to some existing Stata code for simulating static panel
data models?
And particularly random effects models.
*------------- begin example -------------
// for reproducability
set seed 123456

// start with an empty dataset
drop _all

// 20 level 2 groups
set obs 20

// create group identifier
gen group = _n

// a level 2 binary explanatory variable
gen z1 = runiform() < .5

// level 2 error term (sd = .5)
gen u2 = .5*rnormal()

// 5 level 1 observations per level 2 group
expand 5

// a level 1 explanatory variable
// (which is influenced by z1)
gen x1 = rnormal() + .5*z1

// a level 1 error term (sd = .75)
gen u1 = .75*rnormal()

// the dependent variable
gen y = 1 + .5*x1 - z1 + u1 + u2

// estimate the model
xtreg y x1 z1, i(group)
*-------------- end example --------------
(For more on examples I sent to the Statalist see:
http://www.maartenbuis.nl/example_faq )

Hope this helps,
Maarten

---------------------------------
Maarten L. Buis
WZB
Reichpietschufer 50
10785 Berlin
Germany

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


--
Dr. M. Weeks
Senior Lecturer in Economics
University of Cambridge

Fellow of Clare College

t. (+44) 01223 335260
f. (+44) 01223 335959

e.        [email protected]

w.        http://www.econ.cam.ac.uk/faculty/

DCM V2.0  http://www.econ.cam.ac.uk/DCM2/

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


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