-------------------------------------------------------------------------------- log: d:\activeLS\addobs\work\addobs-eg1.log log type: text opened on: 21 May 2009, 14:34:30 . . // program: addobs-eg1.do . // task: show how to add observations and make predictions with addobs . // project: addobs . // author: jsl \ 19May2009 . . // #0 . // program setup . . version 10 . clear all . set linesize 80 . matrix drop _all . . which addobs .\addobs.ado *! version 0.2.1 2009-05-20 scott long . . // #1 . // load datga . . spex binlfp3, clear . use "http://www.indiana.edu/~jslsoc/stata/spex_data/binlfp3.dta", clear . list in 1 +------------------------------------------------------------------+ | lfp k5 k618 age wc hc lwg inc | |------------------------------------------------------------------| 1. | 0NotInLF 0 3 39 0NoCol 0NoCol .8532125 28.363 | +------------------------------------------------------------------+ . local last = _N . list in `last' +--------------------------------------------------------------+ | lfp k5 k618 age wc hc lwg inc | |--------------------------------------------------------------| 753. | 1InLF 1 0 32 0NoCol 0NoCol 1.210165 10.91 | +--------------------------------------------------------------+ . sum Variable | Obs Mean Std. Dev. Min Max -------------+-------------------------------------------------------- lfp | 753 .5683931 .4956295 0 1 k5 | 753 .2377158 .523959 0 3 k618 | 753 1.353254 1.319874 0 8 age | 753 42.53785 8.072574 30 60 wc | 753 .2815405 .4500494 0 1 -------------+-------------------------------------------------------- hc | 753 .3917663 .4884694 0 1 lwg | 753 1.097115 .5875564 -2.054124 3.218876 inc | 753 20.12897 11.6348 -.0290001 96 . . /* > lfp 753 .5683931 .4956295 0 1 > k5 753 .2377158 .523959 0 3 > k618 753 1.353254 1.319874 0 8 > age 753 42.53785 8.072574 30 60 > wc 753 .2815405 .4500494 0 1 > hc 753 .3917663 .4884694 0 1 > lwg 753 1.097115 .5875564 -2.054124 3.218876 > inc 753 20.12897 11. > */ . . // #2 . // add without svy . . * add row and make prediction . logit lfp k5 k618 age wc hc lwg inc, nolog Logistic regression Number of obs = 753 LR chi2(7) = 124.48 Prob > chi2 = 0.0000 Log likelihood = -452.63296 Pseudo R2 = 0.1209 ------------------------------------------------------------------------------ lfp | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- k5 | -1.462913 .1970006 -7.43 0.000 -1.849027 -1.076799 k618 | -.0645707 .0680008 -0.95 0.342 -.1978499 .0687085 age | -.0628706 .0127831 -4.92 0.000 -.0879249 -.0378162 wc | .8072738 .2299799 3.51 0.000 .3565215 1.258026 hc | .1117336 .2060397 0.54 0.588 -.2920969 .515564 lwg | .6046931 .1508176 4.01 0.000 .3090961 .9002901 inc | -.0344464 .0082084 -4.20 0.000 -.0505346 -.0183583 _cons | 3.18214 .6443751 4.94 0.000 1.919188 4.445092 ------------------------------------------------------------------------------ . addobs, x(age=10) mean(lfp k5 k618 wc hc lwg inc) Row 754 added to 753 rows. Changed values are: age lfp k5 k618 wc hc lwg > inc 754. 10 .5683931 .2377158 1.353254 .2815405 .3917663 1.097115 2 > 0.12897 . addobs, x(age=20) mean(lfp k5 k618 wc hc lwg inc) Row 755 added to 754 rows. Changed values are: age lfp k5 k618 wc hc lwg > inc 755. 20 .5683931 .2377158 1.353254 .2815405 .3917663 1.097115 2 > 0.12897 . predict p1 in 754/755 (option pr assumed; Pr(lfp)) (753 missing values generated) . list age p1 in 754/755 +----------------+ | age p1 | |----------------| 754. | 10 .9136783 | 755. | 20 .8495009 | +----------------+ . prvalue, x(age=10) logit: Predictions for lfp Confidence intervals by delta method 95% Conf. Interval Pr(y=1InLF|x): 0.9137 [ 0.8473, 0.9800] Pr(y=0NotInLF|x): 0.0863 [ 0.0200, 0.1527] k5 k618 age wc hc lwg inc x= .2377158 1.3532537 10 .2815405 .39176627 1.0971148 20.128965 . prvalue, x(age=20) logit: Predictions for lfp Confidence intervals by delta method 95% Conf. Interval Pr(y=1InLF|x): 0.8495 [ 0.7732, 0.9258] Pr(y=0NotInLF|x): 0.1505 [ 0.0742, 0.2268] k5 k618 age wc hc lwg inc x= .2377158 1.3532537 20 .2815405 .39176627 1.0971148 20.128965 . . addobs, x(age=10) mean(inc) Row 756 added to 755 rows. Changed values are: age inc 756. 10 20.12897 . addobs, row(753) x(age=10) addsd(inc) Row 753 modified among 756 rows. Changed values are: age inc 753. 10 22.52166 . . // #3 . // with svy . use svydata_ki, clear (Survey data sample dataset from RTI KI dataset \ 2009-05-19) . svyset, clear . svyset [pweight=c7], strata(c2) pweight: c7 VCE: linearized Single unit: missing Strata 1: c2 SU 1: FPC 1: . /* > id ID > c7 > c2 > age Age > agesq Age squared > attrpart Is partner attractive? > attrself Are you attractive? > black Black (1=yes) > college Have a college degree? (1=yes) > income Income in thousands (midpoints) > income2log Log of income in thousands > ownsex How good is own sexuality-3cat(2nd Q) > sexacts # Sexual acts w/ ptnr > white White (1=yes) > */ . svy: logit attrself white age agesq sexacts, or (running logit on estimation sample) Survey: Logistic regression Number of strata = 7 Number of obs = 814 Number of PSUs = 814 Population size = 43599384 Design df = 807 F( 4, 804) = 4.75 Prob > F = 0.0009 ------------------------------------------------------------------------------ | Linearized attrself | Odds Ratio Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- white | .4833853 .1270188 -2.77 0.006 .2885944 .809653 age | .8770917 .0591874 -1.94 0.052 .7682781 1.001317 agesq | 1.00141 .0008049 1.75 0.080 .9998313 1.002991 sexacts | 1.030213 .0128835 2.38 0.018 1.005232 1.055815 ------------------------------------------------------------------------------ . addobs, mean(attrself white age agesq sexacts) /// > lin(age) squ(agesq) Row 815 added to 814 rows. Changed values are: attrself white age agesq sexacts 815. .6339067 .6855036616 39.29729843 1544.278 12.80467 . predict p1 in 814/815 (option pr assumed; Pr(attrself)) (813 missing values generated) . list attrself white age agesq sexacts p1 in 814/815, clean attrself white age agesq sexacts p1 814. 0SelfNot Black 26 676 14 .8122036 815. .6339067 .6855036616 39.29729843 1544.278 12.80467 .6011155 . . log close log: d:\activeLS\addobs\work\addobs-eg1.log log type: text closed on: 21 May 2009, 14:34:32 --------------------------------------------------------------------------------