Statalist


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

Re: st: How to Plot Panel Data Models or Fitted Curves


From   Maarten buis <maartenbuis@yahoo.co.uk>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: How to Plot Panel Data Models or Fitted Curves
Date   Tue, 30 Jun 2009 09:28:20 +0000 (GMT)

--- On Mon, 29/6/09, John Simpson wrote:
> I have a large set of panel data generated by a series of
> agent-based computer simulations.  There are thousands
> of panels holding high-level population statistics and many
> are unbalanced.  I would like to set aside plotting the
> panels individually and avoid overlaying the panels (there
> are just too many) so xtline seems to not be an option for
> me.
> 
> What I would like is a fitted curve that is based on these
> panels and that includes the confidence interval as a shaded
> area.  This needs to be done for all the panels and for
> specific subsets that meet certain criteria.

I am not quite sure what kind of graph you have in mind, but
does the following example get you closer to what you want?

*--------------- begin example -------------------------------
webuse nlswork, clear

// -mkspline- with the -cubic- option creates creates a
// smooth flexible non-linear function
mkspline sp_ten= tenure, cubic nknots(3)
mkspline sp_age = age, cubic nknots(3)

// -orthog- makes the variables orthogonal (uncorrelated)
// which helps -xtmixed- achieve convergence
orthog sp_ten*, gen(o_sp_ten*)
orthog sp_age*, gen(o_sp_age*)

xtmixed ln_w grade o_sp_age* ttl_exp o_sp_ten* || id:o_sp_ten*

// I am going to drastically alter the data just for 
// plotting purposes. With -preserve- I can afterwards
// easily return to normal data by typing -restore-.
preserve

// set age at the median value
sum age, detail
sum o_sp_age1 if age == r(p50), meanonly
replace o_sp_age1 = r(mean)
sum age, detail
sum o_sp_age2 if age == r(p50), meanonly
replace o_sp_age2 = r(mean)

// set ttl_exp and grade at median value
sum ttl_exp, detail
replace ttl_exp = r(p50)
sum grade, detail
replace grade = r(p50) 

// keep only one observation per value of tenure
// this will keep the graph smaller in terms of
// memory without loosing any information
bys tenure: keep if _n == 1

// create predicted log wages and their standard error
predict fixed, xb
predict se, stdp

// turn this in the lower and upper bounds of the 
// confidence interval
gen lb = fixed - 1.96*se
gen ub = fixed + 1.96*se

// plot
twoway rarea lb ub tenure || line fixed tenure
restore
*--------------- end example -----------------------

Hope this helps,
Maarten

-----------------------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany

http://home.fsw.vu.nl/m.buis/
-----------------------------------------




      

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



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