. set matsize 11000

. cd /Users/robertyaffee/Documents/data/research/chwk/phase4/survival/soma/somaintro
/Users/robertyaffee/Documents/data/research/chwk/phase4/survival/soma/somaIntro

. use soma27sep2013final, clear

. save newsomafinalbkup, replace
file newsomafinalbkup.dta saved

.
.
. di c(pwd)
/Users/robertyaffee/Documents/data/research/chwk/phase4/survival/soma/somaIntro

. di c(filename)
newsomafinalbkup.dta

. di c(os)
MacOSX

. di c(osdtl)
10.6.8

. global user Robert Alan Yaffee

.
. di "$user"
Robert Alan Yaffee

.
. title "Soma setup"


*******************************************************************************
*******************************************************************************
*****                                                                     *****
*****                                                                     *****
*****                             Soma setup                              *****
*****                                                                     *****
*****                                                                     *****
*****                                            27 Sep 2013    23:14:31  *****
*******************************************************************************
*******************************************************************************


.
. di _N
624

. title stset up


*******************************************************************************
*******************************************************************************
*****                                                                     *****
*****                                                                     *****
*****                               stset                                 *****
*****                                 up                                  *****
*****                                                                     *****
*****                                                                     *****
*****                                            27 Sep 2013    23:14:31  *****
*******************************************************************************
*******************************************************************************


. stset, clear

. stset endate, id(id) failure(event==1) enter(time bgdate) exit(time .)

                id:  id
     failure event:  event == 1
obs. time interval:  (endate[_n-1], endate]
 enter on or after:  time bgdate
 exit on or before:  time .

------------------------------------------------------------------------------
      624  total observations
        0  exclusions
------------------------------------------------------------------------------
      624  observations remaining, representing
      236  subjects
      624  failures in multiple-failure-per-subject data
     8116  total analysis time at risk and under observation
                                              at risk from t =         0
                                   earliest observed entry t =        40
                                        last observed exit t =       100

.
. stdes

         failure _d:  event == 1
   analysis time _t:  endate
  enter on or after:  time bgdate
  exit on or before:  time .
                 id:  id

                                   +-------------- per subject --------------+
Category                   total        mean         min     median        max
------------------------------------------------------------------------------
no. of subjects              236
no. of records               624    2.644068           1          2          8

(first) entry time                        40          40         40         40
(final) exit time                   74.38983          41         78        100

subjects with gap              0
time on gap if gap             0           .           .          .          .
time at risk                8116    34.38983           1         38         60

failures                     624    2.644068           1          2          8
------------------------------------------------------------------------------

.
. cd /Users/robertyaffee/Documents/data/research/chwk/phase4/survival/soma/somaIntro
/Users/robertyaffee/Documents/data/research/chwk/phase4/survival/soma/somaIntro

.
.
. cap gen illwgp = 1 if illw < 3

.    replace illwgp = 2 if illw > 2 & illw < 5
(0 real changes made)

.    replace illwgp = 3 if illw > 4 & illw < 7
(0 real changes made)

.    cap label define ilgp 1 "0-2" 2 "3 - 4" 3 "5-6,inc"

.    label values illwgp ilgp

.    label var illwgp "Self-reported illness category"

.  cap dummies agegp

.  cap dummies educ

.
.
.  save soma27sep2013final, replace
file soma27sep2013final.dta saved

.
.
.
. set more off

. title "Male data descriptioon"


*******************************************************************************
*******************************************************************************
*****                                                                     *****
*****                                                                     *****
*****                       Male data descriptioon                        *****
*****                                                                     *****
*****                                                                     *****
*****                                            27 Sep 2013    23:14:31  *****
*******************************************************************************
*******************************************************************************


. stdes if gender==1

         failure _d:  event == 1
   analysis time _t:  endate
  enter on or after:  time bgdate
  exit on or before:  time .
                 id:  id

                                   +-------------- per subject --------------+
Category                   total        mean         min     median        max
------------------------------------------------------------------------------
no. of subjects               98
no. of records               249    2.540816           1          2          8

(first) entry time                        40          40         40         40
(final) exit time                   74.32653          41         78         96

subjects with gap              0
time on gap if gap             0           .           .          .          .
time at risk                3364    34.32653           1         38         56

failures                     249    2.540816           1          2          8
------------------------------------------------------------------------------

. sts graph if gender==1, xline(52) title(Male somatic survival probability)  ///
>   ttext( 0.25 50 "Chornobyl", orientation(vertical)) ///
>   ytitle(Conditional probability of no somatization)  ///
>   note(time axis legend 0=1960 40=1980 52=1986 60=1990 80=2000 100=2010)

         failure _d:  event == 1
   analysis time _t:  endate
  enter on or after:  time bgdate
  exit on or before:  time .
                 id:  id

. graph save somasurvm.gph, replace
(file somasurvm.gph saved)

. graph export somasurvm.pdf, replace
(file /Users/robertyaffee/Documents/data/research/chwk/phase4/survival/soma/somaIntro/somasurvm.pdf written in PDF format)

.
.
. title "Male survival probability table"


*******************************************************************************
*******************************************************************************
*****                                                                     *****
*****                                                                     *****
*****                  Male survival probability table                    *****
*****                                                                     *****
*****                                                                     *****
*****                                            27 Sep 2013    23:14:33  *****
*******************************************************************************
*******************************************************************************


. sts list if gender==1

         failure _d:  event == 1
   analysis time _t:  endate
  enter on or after:  time bgdate
  exit on or before:  time .
                 id:  id

           Beg.          Net            Survivor      Std.
  Time    Total   Fail   Lost           Function     Error     [95% Conf. Int.]
-------------------------------------------------------------------------------
    40        0      0    -98             1.0000         .          .         .
    41       98      4     -2             0.9592    0.0200     0.8949    0.9845
    42       96      1      0             0.9492    0.0221     0.8822    0.9785
    44       95      2     -2             0.9292    0.0258     0.8573    0.9656
    46       95      3     -2             0.8999    0.0300     0.8219    0.9448
    48       94      3     -2             0.8711    0.0333     0.7885    0.9230
    50       93      4     -4             0.8337    0.0368     0.7463    0.8931
    52       93     29    -17             0.5737    0.0474     0.4754    0.6602
    54       81      6     -5             0.5312    0.0469     0.4353    0.6181
    56       80     12     -8             0.4515    0.0452     0.3615    0.5372
    58       76     11     -9             0.3862    0.0427     0.3027    0.4688
    60       74      4     -4             0.3653    0.0417     0.2844    0.4464
    62       74      7     -4             0.3307    0.0397     0.2544    0.4089
    64       71     13    -11             0.2702    0.0358     0.2027    0.3420
    66       69      6     -5             0.2467    0.0340     0.1832    0.3153
    68       68      3     -2             0.2358    0.0330     0.1743    0.3028
    70       67     16    -12             0.1795    0.0280     0.1285    0.2375
    72       63     13    -11             0.1425    0.0240     0.0994    0.1931
    74       61      8     -4             0.1238    0.0218     0.0851    0.1701
    76       57     15     -8             0.0912    0.0176     0.0606    0.1294
    78       50     10     -7             0.0730    0.0150     0.0472    0.1060
    80       47     18    -12             0.0450    0.0106     0.0274    0.0691
    82       41     11     -3             0.0329    0.0084     0.0193    0.0523
    84       33      7     -5             0.0260    0.0070     0.0147    0.0424
    86       31      9     -5             0.0184    0.0054     0.0099    0.0314
    88       27     11     -4             0.0109    0.0036     0.0054    0.0201
    90       20      8     -3             0.0065    0.0025     0.0029    0.0131
    92       15      8      0             0.0031    0.0014     0.0011    0.0072
    94        7      4      0             0.0013    0.0008     0.0003    0.0041
    96        3      3      0             0.0000         .          .         .
-------------------------------------------------------------------------------

.
. sts graph if gender==2, xline(52) title(Female somatic survival probability) ///
>   ttext(.5 50 "Chornobyl", orientation(vertical)) ///
>   ytitle(Conditional probability of no somatization) ///
>   note(time axis legend 0=1960 40=1980 52=1986 60=1990 80=2000 100=2010)

         failure _d:  event == 1
   analysis time _t:  endate
  enter on or after:  time bgdate
  exit on or before:  time .
                 id:  id

.   graph save somasurvf.gph, replace
(file somasurvf.gph saved)

.   graph export somasurf.pdf, replace
(file /Users/robertyaffee/Documents/data/research/chwk/phase4/survival/soma/somaIntro/somasurf.pdf written in PDF format)

.
.  title "Female survival probability table"


*******************************************************************************
*******************************************************************************
*****                                                                     *****
*****                                                                     *****
*****                 Female survival probability table                   *****
*****                                                                     *****
*****                                                                     *****
*****                                            27 Sep 2013    23:14:34  *****
*******************************************************************************
*******************************************************************************


.  sts list if gender==2

         failure _d:  event == 1
   analysis time _t:  endate
  enter on or after:  time bgdate
  exit on or before:  time .
                 id:  id

           Beg.          Net            Survivor      Std.
  Time    Total   Fail   Lost           Function     Error     [95% Conf. Int.]
-------------------------------------------------------------------------------
    40        0      0   -138             1.0000         .          .         .
    41      138      5     -4             0.9638    0.0159     0.9151    0.9848
    42      137      2     -1             0.9497    0.0185     0.8974    0.9757
    44      136      6     -6             0.9078    0.0244     0.8465    0.9454
    45      136      3     -3             0.8878    0.0264     0.8234    0.9297
    46      136      8     -7             0.8356    0.0306     0.7649    0.8866
    48      135      5     -5             0.8046    0.0325     0.7314    0.8598
    50      135      5     -2             0.7748    0.0339     0.6997    0.8334
    52      132     37    -24             0.5576    0.0389     0.4780    0.6299
    54      119     11     -9             0.5061    0.0383     0.4288    0.5782
    56      117     18    -12             0.4282    0.0365     0.3560    0.4984
    58      111     13     -7             0.3781    0.0348     0.3101    0.4457
    60      105     17    -13             0.3169    0.0322     0.2550    0.3804
    62      101     13    -11             0.2761    0.0300     0.2191    0.3359
    64       99     16    -13             0.2315    0.0271     0.1805    0.2863
    66       96     13     -8             0.2001    0.0248     0.1540    0.2507
    68       91     18    -16             0.1605    0.0216     0.1209    0.2052
    70       89      9     -8             0.1443    0.0201     0.1077    0.1861
    72       88     30    -22             0.0951    0.0151     0.0682    0.1273
    73       80      1      0             0.0939    0.0150     0.0673    0.1258
    74       79      9     -9             0.0832    0.0137     0.0590    0.1126
    76       79     22    -12             0.0600    0.0107     0.0414    0.0834
    78       69     18    -14             0.0444    0.0085     0.0297    0.0633
    80       65     15     -8             0.0341    0.0070     0.0223    0.0498
    82       58      7     -6             0.0300    0.0063     0.0194    0.0442
    84       57     19     -9             0.0200    0.0046     0.0124    0.0306
    86       47     12     -3             0.0149    0.0037     0.0090    0.0235
    88       38     14     -4             0.0094    0.0026     0.0053    0.0156
    90       28     15     -1             0.0044    0.0015     0.0021    0.0082
    92       14      5      0             0.0028    0.0011     0.0012    0.0058
    94        9      6      0             0.0009    0.0006     0.0003    0.0028
    96        3      2      0             0.0003    0.0003     0.0000    0.0018
   100        1      1      0             0.0000         .          .         .
-------------------------------------------------------------------------------

.
.
.
. title "Discrete variable tests"


*******************************************************************************
*******************************************************************************
*****                                                                     *****
*****                                                                     *****
*****                      Discrete variable tests                        *****
*****                                                                     *****
*****                                                                     *****
*****                                            27 Sep 2013    23:14:34  *****
*******************************************************************************
*******************************************************************************


.
. foreach var in gender agegp cohort cumdosewgp percRiskgp illwgp {
  2. sts test `var', logrank
  3. sts test `var', wilcoxon
  4. }

         failure _d:  event == 1
   analysis time _t:  endate
  enter on or after:  time bgdate
  exit on or before:  time .
                 id:  id


Log-rank test for equality of survivor functions


          |   Events         Events
gender    |  observed       expected
----------+-------------------------
1. male   |       249         259.79
2. female |       375         364.21
----------+-------------------------
Total     |       624         624.00

                chi2(1) =       0.99
                Pr>chi2 =     0.3193

         failure _d:  event == 1
   analysis time _t:  endate
  enter on or after:  time bgdate
  exit on or before:  time .
                 id:  id


Wilcoxon (Breslow) test for equality of survivor functions


          |   Events         Events        Sum of
gender    |  observed       expected        ranks
----------+--------------------------------------
1. male   |       249         259.79        -2270
2. female |       375         364.21         2270
----------+--------------------------------------
Total     |       624         624.00            0

                chi2(1) =       1.60
                Pr>chi2 =     0.2056

         failure _d:  event == 1
   analysis time _t:  endate
  enter on or after:  time bgdate
  exit on or before:  time .
                 id:  id


Log-rank test for equality of survivor functions


           |   Events         Events
agegp      |  observed       expected
-----------+-------------------------
28 thru 42 |       141         142.61
43 thru 55 |       240         206.36
56 thru 84 |       243         275.03
-----------+-------------------------
Total      |       624         624.00

                 chi2(2) =      12.04
                 Pr>chi2 =     0.0024

         failure _d:  event == 1
   analysis time _t:  endate
  enter on or after:  time bgdate
  exit on or before:  time .
                 id:  id


Wilcoxon (Breslow) test for equality of survivor functions


           |   Events         Events        Sum of
agegp      |  observed       expected        ranks
-----------+--------------------------------------
28 thru 42 |       141         142.61        -1390
43 thru 55 |       240         206.36         5405
56 thru 84 |       243         275.03        -4015
-----------+--------------------------------------
Total      |       624         624.00            0

                 chi2(2) =       9.94
                 Pr>chi2 =     0.0069

         failure _d:  event == 1
   analysis time _t:  endate
  enter on or after:  time bgdate
  exit on or before:  time .
                 id:  id


Log-rank test for equality of survivor functions


                   |   Events         Events
cohort             |  observed       expected
-------------------+-------------------------
Born < 1954        |       246         258.43
1954 < born < 1967 |        90          81.17
born > 1967        |        79          75.40
-------------------+-------------------------
Total              |       415         415.00

                         chi2(2) =       2.25
                         Pr>chi2 =     0.3249

         failure _d:  event == 1
   analysis time _t:  endate
  enter on or after:  time bgdate
  exit on or before:  time .
                 id:  id


Wilcoxon (Breslow) test for equality of survivor functions


                   |   Events         Events        Sum of
cohort             |  observed       expected        ranks
-------------------+--------------------------------------
Born < 1954        |       246         258.43         -861
1954 < born < 1967 |        90          81.17          911
born > 1967        |        79          75.40          -50
-------------------+--------------------------------------
Total              |       415         415.00            0

                         chi2(2) =       1.38
                         Pr>chi2 =     0.5018

         failure _d:  event == 1
   analysis time _t:  endate
  enter on or after:  time bgdate
  exit on or before:  time .
                 id:  id


Log-rank test for equality of survivor functions


           |   Events         Events
cumdosewgp |  observed       expected
-----------+-------------------------
low        |       365         315.40
high       |       259         308.60
-----------+-------------------------
Total      |       624         624.00

                 chi2(1) =      20.65
                 Pr>chi2 =     0.0000

         failure _d:  event == 1
   analysis time _t:  endate
  enter on or after:  time bgdate
  exit on or before:  time .
                 id:  id


Wilcoxon (Breslow) test for equality of survivor functions


           |   Events         Events        Sum of
cumdosewgp |  observed       expected        ranks
-----------+--------------------------------------
low        |       365         315.40         8534
high       |       259         308.60        -8534
-----------+--------------------------------------
Total      |       624         624.00            0

                 chi2(1) =      22.49
                 Pr>chi2 =     0.0000

         failure _d:  event == 1
   analysis time _t:  endate
  enter on or after:  time bgdate
  exit on or before:  time .
                 id:  id


Log-rank test for equality of survivor functions


           |   Events         Events
percRiskgp |  observed       expected
-----------+-------------------------
low        |       117          92.86
medium     |       266         271.65
high       |       241         259.49
-----------+-------------------------
Total      |       624         624.00

                 chi2(2) =      10.01
                 Pr>chi2 =     0.0067

         failure _d:  event == 1
   analysis time _t:  endate
  enter on or after:  time bgdate
  exit on or before:  time .
                 id:  id


Wilcoxon (Breslow) test for equality of survivor functions


           |   Events         Events        Sum of
percRiskgp |  observed       expected        ranks
-----------+--------------------------------------
low        |       117          92.86         6175
medium     |       266         271.65        -3692
high       |       241         259.49        -2483
-----------+--------------------------------------
Total      |       624         624.00            0

                 chi2(2) =      20.26
                 Pr>chi2 =     0.0000

         failure _d:  event == 1
   analysis time _t:  endate
  enter on or after:  time bgdate
  exit on or before:  time .
                 id:  id


Log-rank test for equality of survivor functions


        |   Events         Events
illwgp  |  observed       expected
--------+-------------------------
0-2     |       515         506.80
3 - 4   |        86          92.11
5-6,inc |        23          25.08
--------+-------------------------
Total   |       624         624.00

              chi2(2) =       0.96
              Pr>chi2 =     0.6195

         failure _d:  event == 1
   analysis time _t:  endate
  enter on or after:  time bgdate
  exit on or before:  time .
                 id:  id


Wilcoxon (Breslow) test for equality of survivor functions


        |   Events         Events        Sum of
illwgp  |  observed       expected        ranks
--------+--------------------------------------
0-2     |       515         506.80         2988
3 - 4   |        86          92.11        -2290
5-6,inc |        23          25.08         -698
--------+--------------------------------------
Total   |       624         624.00            0

              chi2(2) =       5.43
              Pr>chi2 =     0.0662

.
.
. title "Discrete variable survival and hazard rates"


*******************************************************************************
*******************************************************************************
*****                                                                     *****
*****                                                                     *****
*****            Discrete variable survival and hazard rates              *****
*****                                                                     *****
*****                                                                     *****
*****                                            27 Sep 2013    23:14:35  *****
*******************************************************************************
*******************************************************************************


. foreach var in gender agegp cohort cumdosewgp percRiskgp illwgp {
  2. set more off
  3. sts graph, by(`var') title(Survival function) xline(52) ci ///
>   subtitle("for `var'")
  4.    graph save survgp`var'.gph, replace
  5.    graph export survgp`var'.pdf, replace
  6. sts graph, haz by(`var') ci title("Smoothed hazard rate by `var'")
  7.    graph save hazgp`var'.gph, replace
  8.    graph export hazgp`var'.pdf, replace
  9. sts graph, cumhaz  by(`var') ci title("Cumulative hazard rate of `var'")
 10.    graph save cumhazgp`var'.gph, replace
 11.    graph export cumhazgp`var'.pdf, replace
 12. }

         failure _d:  event == 1
   analysis time _t:  endate
  enter on or after:  time bgdate
  exit on or before:  time .
                 id:  id
(file survgpgender.gph saved)
(file /Users/robertyaffee/Documents/data/research/chwk/phase4/survival/soma/somaIntro/survgpgender.pdf written in PDF format)

         failure _d:  event == 1
   analysis time _t:  endate
  enter on or after:  time bgdate
  exit on or before:  time .
                 id:  id
(file hazgpgender.gph saved)
(file /Users/robertyaffee/Documents/data/research/chwk/phase4/survival/soma/somaIntro/hazgpgender.pdf written in PDF format)

         failure _d:  event == 1
   analysis time _t:  endate
  enter on or after:  time bgdate
  exit on or before:  time .
                 id:  id
(file cumhazgpgender.gph saved)
(file /Users/robertyaffee/Documents/data/research/chwk/phase4/survival/soma/somaIntro/cumhazgpgender.pdf written in PDF format)

         failure _d:  event == 1
   analysis time _t:  endate
  enter on or after:  time bgdate
  exit on or before:  time .
                 id:  id
(file survgpagegp.gph saved)
(file /Users/robertyaffee/Documents/data/research/chwk/phase4/survival/soma/somaIntro/survgpagegp.pdf written in PDF format)

         failure _d:  event == 1
   analysis time _t:  endate
  enter on or after:  time bgdate
  exit on or before:  time .
                 id:  id
(file hazgpagegp.gph saved)
(file /Users/robertyaffee/Documents/data/research/chwk/phase4/survival/soma/somaIntro/hazgpagegp.pdf written in PDF format)

         failure _d:  event == 1
   analysis time _t:  endate
  enter on or after:  time bgdate
  exit on or before:  time .
                 id:  id
(file cumhazgpagegp.gph saved)
(file /Users/robertyaffee/Documents/data/research/chwk/phase4/survival/soma/somaIntro/cumhazgpagegp.pdf written in PDF format)

         failure _d:  event == 1
   analysis time _t:  endate
  enter on or after:  time bgdate
  exit on or before:  time .
                 id:  id
(file survgpcohort.gph saved)
(file /Users/robertyaffee/Documents/data/research/chwk/phase4/survival/soma/somaIntro/survgpcohort.pdf written in PDF format)

         failure _d:  event == 1
   analysis time _t:  endate
  enter on or after:  time bgdate
  exit on or before:  time .
                 id:  id
(file hazgpcohort.gph saved)
(file /Users/robertyaffee/Documents/data/research/chwk/phase4/survival/soma/somaIntro/hazgpcohort.pdf written in PDF format)

         failure _d:  event == 1
   analysis time _t:  endate
  enter on or after:  time bgdate
  exit on or before:  time .
                 id:  id
(file cumhazgpcohort.gph saved)
(file /Users/robertyaffee/Documents/data/research/chwk/phase4/survival/soma/somaIntro/cumhazgpcohort.pdf written in PDF format)

         failure _d:  event == 1
   analysis time _t:  endate
  enter on or after:  time bgdate
  exit on or before:  time .
                 id:  id
(file survgpcumdosewgp.gph saved)
(file /Users/robertyaffee/Documents/data/research/chwk/phase4/survival/soma/somaIntro/survgpcumdosewgp.pdf written in PDF format)

         failure _d:  event == 1
   analysis time _t:  endate
  enter on or after:  time bgdate
  exit on or before:  time .
                 id:  id
(file hazgpcumdosewgp.gph saved)
(file /Users/robertyaffee/Documents/data/research/chwk/phase4/survival/soma/somaIntro/hazgpcumdosewgp.pdf written in PDF format)

         failure _d:  event == 1
   analysis time _t:  endate
  enter on or after:  time bgdate
  exit on or before:  time .
                 id:  id
(file cumhazgpcumdosewgp.gph saved)
(file /Users/robertyaffee/Documents/data/research/chwk/phase4/survival/soma/somaIntro/cumhazgpcumdosewgp.pdf written in PDF format)

         failure _d:  event == 1
   analysis time _t:  endate
  enter on or after:  time bgdate
  exit on or before:  time .
                 id:  id
(file survgppercRiskgp.gph saved)
(file /Users/robertyaffee/Documents/data/research/chwk/phase4/survival/soma/somaIntro/survgppercRiskgp.pdf written in PDF format)

         failure _d:  event == 1
   analysis time _t:  endate
  enter on or after:  time bgdate
  exit on or before:  time .
                 id:  id
(file hazgppercRiskgp.gph saved)
(file /Users/robertyaffee/Documents/data/research/chwk/phase4/survival/soma/somaIntro/hazgppercRiskgp.pdf written in PDF format)

         failure _d:  event == 1
   analysis time _t:  endate
  enter on or after:  time bgdate
  exit on or before:  time .
                 id:  id
(file cumhazgppercRiskgp.gph saved)
(file /Users/robertyaffee/Documents/data/research/chwk/phase4/survival/soma/somaIntro/cumhazgppercRiskgp.pdf written in PDF format)

         failure _d:  event == 1
   analysis time _t:  endate
  enter on or after:  time bgdate
  exit on or before:  time .
                 id:  id
(file survgpillwgp.gph saved)
(file /Users/robertyaffee/Documents/data/research/chwk/phase4/survival/soma/somaIntro/survgpillwgp.pdf written in PDF format)

         failure _d:  event == 1
   analysis time _t:  endate
  enter on or after:  time bgdate
  exit on or before:  time .
                 id:  id
(file hazgpillwgp.gph saved)
(file /Users/robertyaffee/Documents/data/research/chwk/phase4/survival/soma/somaIntro/hazgpillwgp.pdf written in PDF format)

         failure _d:  event == 1
   analysis time _t:  endate
  enter on or after:  time bgdate
  exit on or before:  time .
                 id:  id
(file cumhazgpillwgp.gph saved)
(file /Users/robertyaffee/Documents/data/research/chwk/phase4/survival/soma/somaIntro/cumhazgpillwgp.pdf written in PDF format)

.