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]

[no subject]



For example, using the first 4 waves, first data preparation and then an
analysis: 

// Start by putting data from 4 waves into temporary files, renaming
use pid ancigs asmoke asctype aage using /home/data/bhps/aindresp
gen wave = 1
rename (ancigs asmoke asctype aage) (ncigs smoke sctype age)
save tempfile1,replace

use pid bncigs bsmoke bsctype bage using /home/data/bhps/bindresp
gen wave = 2
rename (bncigs bsmoke bsctype bage) (ncigs smoke sctype age)
save tempfile2,replace


use pid cncigs csmoke csctype cage using /home/data/bhps/cindresp
gen wave = 3
rename (cncigs csmoke csctype cage) (ncigs smoke sctype age)
save tempfile3,replace

use pid dncigs dsmoke dsctype dage using /home/data/bhps/dindresp
gen wave = 4
rename (dncigs dsmoke dsctype dage) (ncigs smoke sctype age)
save tempfile4,replace

// Append the four files
use tempfile1
append using tempfile2
append using tempfile3
append using tempfile4

sort pid wave
// Now you have up to four observations per individual

// School type is not asked after wave 1 except for new entrants
// Thus replace missing values with previous values
// I haven't checked that the categories of wSCTYPE are consistent
// across time; you should do this
mvdecode sctype, mv(-9/-1)
by pid: replace sctype = sctype[_n-1] if missing(sctype)

// Create an new n-cigs figure with 0 for non smokers, and deal with missing values
gen cigarettes = ncigs
replace cigarettes = 0 if smoke == 2
mvdecode cigarettes, mv(-9/-1)

// Simple regression, paying no attention to repeated observations
reg cigarettes i.sctype age

// Regression with standard errors corrected for clustering by PID
reg cigarettes i.sctype age, cluster(pid)

// Cross-sectional time-series regression (panel regression) with random effects by PID
xtreg cigarettes i.sctype age, i(pid) re

-- 
Brendan Halpin, Head, Department of Sociology, University of Limerick, Ireland
Tel: w +353-61-213147  f +353-61-202569  h +353-61-338562;  Room F1-002 x 3147
mailto:[email protected]    ULSociology on Facebook: http://on.fb.me/fjIK9t
http://teaching.sociology.ul.ie/bhalpin/wordpress         twitter:@ULSociology
*
*   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