Demo entry 6678017

hardcore_smoking

   

Submitted by anonymous on Dec 05, 2017 at 03:26
Language: SAS. Code size: 39.8 kB.

LIBNAME A 'C:\Users\Ikhan Kim\Dropbox\´ëÇпø °ü·Ã\2017³â 2Çбâ\ÀÇ·á°ü¸®Çйæ¹ý¼¼¹Ì³ª\Term paper ÀÛ¼º\Data';
LIBNAME DATASET 'C:\Users\Ikhan Kim\Dropbox\work\Dataset\SAS_DATA';

* ¿¬µµº° ¿¬·ÉÇ¥ÁØÈ­ Èí¿¬À², °ñÃÊ Èí¿¬À²;
** Çѱ¹º¹ÁöÆгÎ;
DATA A.HARD_PREV; SET DATASET.Koweps_hp01_11_long_170331;

* YEAR: Á¶»ç±âÁس⵵, YEAR1: Á¶»ç³âµµ, WV: Á¶»çÂ÷¼ö;
YEAR1=YEAR+1;

* IF YEAR1>=2010;

* ¼ºº°;
SEX=H_G3;

* ¿¬·É; 
AGE=YEAR1-H_G4;

IF AGE>=26;

IF 26<=AGE<= 35 THEN AGEC=1;
ELSE IF 35 <=AGE<= 44 THEN AGEC=2;
ELSE IF 45 <=AGE<= 54 THEN AGEC=3;
ELSE IF 55 <=AGE<= 64 THEN AGEC=4;
ELSE IF 65 <=AGE<= 74 THEN AGEC=5;
ELSE IF 75 <=AGE THEN AGEC=6;

* Áö±Ý±îÁö ÇÇ¿î ´ã¹è ÃÑ·®;
IF P05_3AQ1=3 THEN TOTAL_A=0;
ELSE IF P05_3AQ1=1 THEN TOTAL_A=1;
ELSE IF P05_3AQ1=2 THEN TOTAL_A=2;
ELSE IF P05_3AQ1=9 THEN TOTAL_A=.;
ELSE TOTAL_A=.;

* Èí¿¬  ¿©ºÎ (1: ÇÇ¿ò, 2: ÇÇ¿ìÁö ¾ÊÀ½);
C_SMOK=p05_3aq5;
IF p05_3aq5 IN (2) THEN C_SMOK=0;
ELSE IF p05_3aq5 IN (9) THEN C_SMOK=.;

* ÇöÀç Èí¿¬ ¿©ºÎ (1: Èí¿¬, 0: ºñÈí¿¬);
IF C_SMOK IN (1) & TOTAL_A IN (2,.) THEN SMOK=1;
ELSE IF C_SMOK IN (1) & TOTAL_A IN (1) THEN SMOK=0;
ELSE IF C_SMOK IN (0) THEN SMOK=0;
ELSE SMOK=.;

* ÇÏ·ç Æò±Õ Èí¿¬·®;
AMOUNT=p05_3aq6;
IF p05_3aq6 IN (999) THEN AMOUNT=.;

** 15°³ºñ ÀÌ»ó Heavy amount·Î Á¤ÀÇ;
IF AMOUNT >= 15 THEN HEAVY_AMT=1; ELSE IF 0<AMOUNT<15 THEN HEAVY_AMT=0;

* ÃÖ±Ù 1³â°£ ±Ý¿¬ ½Ãµµ (1:¿¹, 2: ¾Æ´Ï¿À);
IF p05_3aq7 IN (1) THEN NO_TRIAL=0;
IF p05_3aq7 IN (2) THEN NO_TRIAL=1;
IF p05_3aq7 IN (9) THEN NO_TRIAL=.;

* ±Ý¿¬ °èȹ (1: 1°³¿ù ¾È, 2: 6°³¿ù ¾È, 3: ¾ðÁ¨°¡´Â ÀÖ´Ù, 4: ÇöÀç·Î¼­´Â ¾ø´Ù);
NO_PLAN=p05_3aq8;
IF p05_3aq8 IN (4) THEN NO_PLAN=1;
ELSE IF p05_3aq8 IN (1,2,3) THEN NO_PLAN=0;
ELSE IF p05_3aq8 IN (9) THEN NO_PLAN=.;

IF SMOK=0 THEN DO;
AMOUNT=0; HEAVY_AMT=0; NO_PLAN=0; NO_TRIAL=0;
END;

KEEP YEAR1 H_PID SEX AGE AGEC TOTAL_A C_SMOK SMOK AMOUNT HEAVY_AMT NO_TRIAL NO_PLAN P_WSC;

RUN;

PROC SORT DATA=A.HARD_PREV; BY H_PID YEAR1; PROC SORT DATA=A.NOPL_TOTAL; BY H_PID YEAR1;
DATA A.HARD_PREV1; MERGE A.HARD_PREV A.NOPL_TOTAL; BY H_PID YEAR1; 
* Hardcore smoker Á¤ÀÇ;
IF SMOK=1 THEN DO;
IF HEAVY_AMT IN (1) & NO_TRIAL IN (1) & NOPL IN (1) THEN HARD=1; ELSE HARD=0;
END;
RUN;

PROC SQL;
CREATE TABLE HARD AS
SELECT *,
SUM(NO_PLAN) AS SUM_NO_PLAN
FROM A.HARD_PREV
WHERE YEAR1 IN (2010:2014)
GROUP BY H_PID;
RUN;

DATA A.HARD1; SET HARD; IF YEAR1 IN (2014); IF AGE>=26 & SMOK=1; IF SUM_NO_PLAN=5 THEN NOPL=1; ELSE NOPL=0; KEEP H_PID NOPL SMOK; RUN;

PROC SORT DATA=A.HARD1; BY HARD;
PROC FREQ DATA=A.HARD1; TABLES NOPL; BY HARD; RUN;
PROC FREQ DATA=A.HARD1; TABLES NOPL; WHERE SMOK=1; RUN;

PROC SORT DATA=A.HARD_PREV; BY SEX YEAR1; 
PROC FREQ DATA=A.HARD_PREV; TABLES SMOK; BY SEX YEAR1; ODS OUTPUT ONEWAYFREQS=R1;RUN; 
PROC FREQ DATA=A.HARD_PREV; TABLES HARD; BY SEX YEAR1; WHERE SMOK=1; ODS OUTPUT ONEWAYFREQS=R2; RUN; 

* ÇöÀç Èí¿¬À²;
PROC SURVEYREG DATA=A.HARD_PREV;
WEIGHT p_wsc; 
DOMAIN SEX * YEAR1;
CLASS AGEC;
MODEL SMOK=AGEC / noint solution clparm vadjust=none;
ESTIMATE AGEC 0.183180922 0.220721957 0.232128656 0.182714784 0.107023789 0.074229892;
ODS OUTPUT ESTIMATES=STD_SMOKING;
RUN;

* °ñÃÊ Èí¿¬À²;
PROC SURVEYREG DATA=A.HARD_PREV1;
WEIGHT p_wsc; 
DOMAIN SEX * YEAR1;
CLASS AGEC;
MODEL HARD=AGEC / noint solution clparm vadjust=none;
ESTIMATE AGEC 0.183180922 0.220721957 0.232128656 0.182714784 0.107023789 0.074229892;
ODS OUTPUT ESTIMATES=STD_HARD;
WHERE SMOK=1;
RUN;

PROC SURVEYREG DATA=A.HARD_PREV1;
WEIGHT p_wsc; 
DOMAIN YEAR1;
CLASS AGEC;
MODEL HARD=AGEC / noint solution clparm vadjust=none;
ESTIMATE AGEC 0.183180922 0.220721957 0.232128656 0.182714784 0.107023789 0.074229892;
ODS OUTPUT ESTIMATES=STD_HARD;
WHERE SMOK=1;
RUN;

* ÇÏ·ç 15°³ºñ ÀÌ»ó Èí¿¬À²;
PROC SURVEYREG DATA=A.HARD_PREV;
WEIGHT p_wsc; 
DOMAIN SEX * YEAR1;
CLASS AGEC;
MODEL HEAVY_AMT=AGEC / noint solution clparm vadjust=none;
ESTIMATE AGEC 0.183180922 0.220721957 0.232128656 0.182714784 0.107023789 0.074229892;
ODS OUTPUT ESTIMATES=STD_HEAVY;
WHERE SMOK=1;
RUN;

* ÃÖ±Ù 1³â°£ ±Ý¿¬ ½Ãµµ;
PROC SURVEYREG DATA=A.HARD_PREV;
WEIGHT p_wsc; 
DOMAIN SEX * YEAR1;
CLASS AGEC;
MODEL NO_TRIAL=AGEC / noint solution clparm vadjust=none;
ESTIMATE AGEC 0.183180922 0.220721957 0.232128656 0.182714784 0.107023789 0.074229892;
ODS OUTPUT ESTIMATES=STD_ATT;
WHERE SMOK=1;
RUN;

* ±Ý¿¬ °èȹ;
PROC SURVEYREG DATA=A.HARD_PREV;
WEIGHT p_wsc; 
DOMAIN SEX * YEAR1;
CLASS AGEC;
MODEL NO_PLAN=AGEC / noint solution clparm vadjust=none;
ESTIMATE AGEC 0.179363577 0.212006411 0.223165988 0.178560022 0.108645814 0.098258187;
ODS OUTPUT ESTIMATES=STD_PLAN;
WHERE SMOK=1;
RUN;

**** ÀÏ¹Ý Èí¿¬ÀÚ subgroup analysis;
* ÇÏ·ç 15°³ºñ ÀÌ»ó Èí¿¬À²;
PROC SURVEYREG DATA=A.HARD_PREV;
WEIGHT p_wsc; 
DOMAIN SEX * YEAR1;
CLASS AGEC;
MODEL HEAVY_AMT=AGEC / noint solution clparm vadjust=none;
ESTIMATE AGEC 0.183180922 0.220721957 0.232128656 0.182714784 0.107023789 0.074229892;
ODS OUTPUT ESTIMATES=STD_HEAVY_NORMAL;
WHERE SMOK=1 & HARD=0;
RUN;

* ÃÖ±Ù 1³â°£ ±Ý¿¬ ½Ãµµ;
PROC SURVEYREG DATA=A.HARD_PREV;
WEIGHT p_wsc; 
DOMAIN SEX * YEAR1;
CLASS AGEC;
MODEL NO_TRIAL=AGEC / noint solution clparm vadjust=none;
ESTIMATE AGEC 0.183180922 0.220721957 0.232128656 0.182714784 0.107023789 0.074229892;
ODS OUTPUT ESTIMATES=STD_ATT_NORMAL;
WHERE SMOK=1 & HARD=0;
RUN;

* ±Ý¿¬ °èȹ;
PROC SURVEYREG DATA=A.HARD_PREV;
WEIGHT p_wsc; 
DOMAIN SEX * YEAR1;
CLASS AGEC;
MODEL NO_PLAN=AGEC / noint solution clparm vadjust=none;
ESTIMATE AGEC 0.179363577 0.212006411 0.223165988 0.178560022 0.108645814 0.098258187;
ODS OUTPUT ESTIMATES=STD_PLAN_NORMAL;
WHERE SMOK=1 & HARD=0;
RUN;


PROC FREQ DATA=A.KWP10; TABLES AGE15 CHILD15; RUN;


* Matching Àü 2014³â µ¥ÀÌÅͼÂ;
DATA KWP9; SET DATASET.Koweps_hpda09_2014_beta3; 

HID=H09_ID;

* ¼ºº°, ID;
SEX14=h09_g3;
H_PID=h09_pid;

* ¿¬·É 19¼¼ ÀÌ»ó;
AGE14=2014-h09_g4;  

IF AGE14>=26;

IF 25<=AGE14<= 35 THEN AGEC=1;
ELSE IF 35 <=AGE14<= 44 THEN AGEC=2;
ELSE IF 45 <=AGE14<= 54 THEN AGEC=3;
ELSE IF 55 <=AGE14<= 64 THEN AGEC=4;
ELSE IF 65 <=AGE14<= 74 THEN AGEC=5;
ELSE IF 75 <=AGE14 THEN AGEC=6;

* Áö±Ý±îÁö ÇÇ¿î ´ã¹è ÃÑ·®;
IF P0905_3AQ1=3 THEN TOTAL_A14=0;
ELSE IF P0905_3AQ1=1 THEN TOTAL_A14=1;
ELSE IF P0905_3AQ1=2 THEN TOTAL_A14=2;
ELSE IF P0905_3AQ1=9 THEN TOTAL_A14=.;
ELSE TOTAL_A14=.;

* Èí¿¬  ¿©ºÎ (1: ÇÇ¿ò, 2: ÇÇ¿ìÁö ¾ÊÀ½);
C_SMOK14=p0905_3aq5;
IF p0905_3aq5 IN (2) THEN C_SMOK14=0;
ELSE IF p0905_3aq5 IN (9) THEN C_SMOK14=.;

* ÇöÀç Èí¿¬ ¿©ºÎ (1: Èí¿¬, 0: ºñÈí¿¬);
IF C_SMOK14 IN (1) & TOTAL_A14 IN (2,.) THEN SMOK14=1;
ELSE IF C_SMOK14 IN (1) & TOTAL_A14 IN (1) THEN SMOK14=0;
ELSE IF C_SMOK14 IN (0) THEN SMOK14=0;
ELSE SMOK14=.;

MISS_SMOK14=(SMOK14=.);
IF SMOK14=. THEN DELETE;

IF SMOK14=1;

* ÇÏ·ç Æò±Õ Èí¿¬·®;
AMOUNT14=p0905_3aq6; IF p0905_3aq6 IN (999) THEN AMOUNT14=.;

MISS_AMOUNT14=(AMOUNT14=.);
IF AMOUNT14=. THEN DELETE;

** 15°³ºñ ÀÌ»ó Heavy amount·Î Á¤ÀÇ;
IF AMOUNT14 >= 15 THEN HEAVY_AMT14=1; ELSE IF 0<AMOUNT14<15 THEN HEAVY_AMT14=0;

* ÃÖ±Ù 1³â°£ ±Ý¿¬ ½Ãµµ (1:¿¹, 2: ¾Æ´Ï¿À);
IF p0905_3aq7 IN (1) THEN NO_TRIAL14=0;
IF p0905_3aq7 IN (2) THEN NO_TRIAL14=1;
IF p0905_3aq7 IN (9) THEN NO_TRIAL14=.;

MISS_TRIAL14=(NO_TRIAL14=.);
IF NO_TRIAL14=. THEN DELETE;
 
* ±Ý¿¬ °èȹ (1: 1°³¿ù ¾È, 2: 6°³¿ù ¾È, 3: ¾ðÁ¨°¡´Â ÀÖ´Ù, 4: ÇöÀç·Î¼­´Â ¾ø´Ù);
NO_PLAN14=p0905_3aq8;
IF p0905_3aq8 IN (4) THEN NO_PLAN14=1;
ELSE IF p0905_3aq8 IN (1,2,3) THEN NO_PLAN14=0;
ELSE IF p0905_3aq8 IN (9) THEN NO_PLAN14=.;

MISS_PLAN14=(NO_PLAN14=.);
IF NO_PLAN14=. THEN DELETE;

* ½Ç³» °ø°£¿¡¼­ ŸÀÎÀÇ ´ã¹è¿¬±â¸¦ ¸ÃÀº ½Ã°£ Á¤µµ (1: 0½Ã°£(¾øÀ½), 2: 1½Ã°£ ¹Ì¸¸, 3: 1½Ã°£ ÀÌ»ó);
IF P0905_3AQ9 IN (1) THEN SECOND_SMOK14=0; 
ELSE IF P0905_3AQ9 IN (2,3) THEN SECOND_SMOK14=1; 
ELSE IF SECOND_SMOK14 IN (9) THEN SECOND_SMOK14=.;
* MISS_SECOND14=(SECOND_SMOK14=.);
* 94¸í;
IF SECOND_SMOK14=. THEN DELETE;

/* ÃÑ Èí¿¬±â°£ 
** ³â;
DUR_YR=p0905_3aq3;
IF p0905_3aq3 IN (99) THEN DUR_YR=.;

** °³¿ù;
DUR_MT=p0905_3aq4; 
IF p0905_3aq4 IN (99) THEN DUR_MT=.; 

 p0905_3aq3 DUR_YR p0905_3aq4 DUR_MT*/

* °¡±¸¿ø¼ö º¸Á¤ °æ»ó °¡±¸¼Òµæ;
FM_SIZE14=SQRT(h0901_1); 
INC14=(h09_cin)/FM_SIZE14;

IF INC14=. OR INC14<=0 THEN MISS_INC14=1;
IF MISS_INC14=1 THEN DELETE;

* ±ÕµîÈ­ ¼Òµæ¿¡ µû¸¥ °¡±¸±¸ºÐ(1: ÀϹݰ¡±¸, 2: Àú¼ÒµæÃþ °¡±¸);
INC_DIST14=h09_hc;

* È¥ÀÎ ¿©ºÎ(1: À¯¹è¿ì, 2: »çº°, 3: ÀÌÈ¥, 4: º°°Å, 5: ¹ÌÈ¥, 6:±âŸ);
IF h09_g10 IN (1) THEN MARR14=1; 
ELSE IF h09_g10 IN (2,3,4) THEN MARR14=2; 
ELSE IF h09_g10 IN (5,6) THEN MARR14=3; 

MISS_MARR14=(MARR14=.);
IF MISS_MARR14=1 THEN DELETE;

* Á¾±³;
RELI14=2-h09_g11;
IF RELI14 IN (0,1);

* ±³À°¼öÁØ;
IF h09_g6 IN (2:4) THEN EDU14=1;
ELSE IF h09_g6 IN (5) THEN EDU14=2;
ELSE IF h09_g6 IN (6:9) THEN EDU14=3;

MISS_EDU14=(EDU14=.);
IF MISS_EDU14=1 THEN DELETE;

* ÁÖ°üÀû °Ç°­¼öÁØ;
IF h09_med2 IN (1,2) THEN SRH14=1; ELSE IF h09_med2 IN (3,4,5) THEN SRH14=0; ELSE SRH14=.;
SRH_SCORE14= 6-h09_med2;

MISS_SRH_SCORE14=(SRH_SCORE14=.);
IF MISS_SRH_SCORE14=1 THEN DELETE;

* 5°³ ±Ç¿ªº° Áö¿ª±¸ºÐ(1.¼­¿ï, 2. ±¤¿ª½Ã, 3.½Ã, 4.±º,5.µµ³óº¹ÇÕ±º), H_REG7: 7°³ ±Ç¿ªº° Áö¿ª±¸ºÐ(1.¼­¿ï, 2.¼öµµ±Ç(ÀÎõ/°æ±â), 3. ºÎ»ê/°æ³²/¿ï»ê, 4.´ë±¸/°æºÏ, 5. ´ëÀü/Ãæ³², 6. °­¿ø/ÃæºÏ, 7. ±¤ÁÖ/Àü³²/ÀüºÏ/Á¦ÁÖµµ;
 IF h09_reg5 IN (1,2) THEN REGION14=1; ELSE IF h09_reg5 IN (3) THEN REGION14=2; ELSE IF h09_reg5 IN (4,5) THEN REGION14=3;
 IF h09_reg5 IN (1,2) THEN METRO14=1; ELSE METRO14=0; 

 MISS_REGION14=(REGION14=.);
 IF MISS_REGION14=1 THEN DELETE;

* À½ÁÖ(1: ¿ù 1ȸ ÀÌÇÏ, 2: ¿ù 2-4ȸ, 3: ÁÖ 2~3ȸ, 4: ÁÖ 4ȸ ÀÌ»ó, 5: ÀüÇô ¸¶½ÃÁö ¾Ê´Â´Ù);
IF p0905_2 IN (1,2) THEN DRK14=2; 
ELSE IF p0905_2 IN (3,4) THEN DRK14=3;
ELSE IF p0905_2 IN (5) THEN DRK14=1;

* À½ÁÖ·® (1: 1-2ÀÜ, 2: 3-4ÀÜ, 3: ÁÖ 5-6ÀÜ, 4: ÁÖ 7-9ÀÜ, 5: 10ÀÜ ÀÌ»ó);
IF p0905_3 IN (1,2,3) THEN DRK_AMT14=1; 
ELSE IF p0905_3 IN (4,5) THEN DRK_AMT14=2;
ELSE IF p0905_3 IN (.,9) THEN DRK_AMT14=0;

* ÇÑ ¹ø¿¡ ¼úÁ¼®¿¡¼­ 6ÀÜ ÀÌ»ó ¸¶½Ã´Â °æ¿ì;
HEAVY_DRK14=p0905_4aq1;
IF p0905_4aq1 IN (2,3,4) THEN HEAVY_DRK14=2;
IF p0905_4aq1 IN (5) THEN HEAVY_DRK14=3;
IF p0905_2 IN (5) THEN HEAVY_DRK14=1;

IF p0905_4aq1 IN (5) THEN HV_DR14=1; ELSE HV_DR14=0;

MISS_HEAVY_DRK14=(HEAVY_DRK14=.);
IF MISS_HEAVY_DRK14=1 THEN DELETE;

* Á÷¾÷ ºÐ·ù;
ECO9=SUBSTR(PUT(h09_eco9,8.),5,2);
ECO=ECO9+0;
/*IF ECO IN (1:3) THEN JOB14=1;
ELSE IF ECO IN (4:9) THEN JOB14=2;
* ELSE IF ECO IN (6:9) THEN JOB14=3;
ELSE IF ECO IN (10) THEN JOB14=3;
ELSE IF H09_ECO9 = . THEN JOB14=3;*/

IF ECO IN (1:3) THEN JOB14=1;
ELSE IF ECO IN (4:5) THEN JOB14=2;
ELSE IF ECO IN (6:9) THEN JOB14=3;
ELSE IF ECO IN (10) THEN JOB14=4;
ELSE IF H09_ECO9 = . THEN JOB14=4;



MISS_JOB14=(JOB14=.);
IF MISS_JOB14=1 THEN DELETE;

* Àü¹ÝÀû ¸¸Á·µµ;
IF p0903_12 IN (1,2) THEN HAPP14=1;
ELSE IF p0903_12 IN (3) THEN HAPP14=2;
ELSE IF p0903_12 IN (4,5) THEN HAPP14=3; 

HAPP_SCORE14=p0903_12;

MISS_HAPP14=(HAPP14=.);
IF MISS_HAPP14=1 THEN DELETE;

* µ¿¹ÝÁúȯ (0: ºñÇØ´ç, 1: 3°³¿ù ¹Ì¸¸, 2: 3-6°³¿ù, 3: 6°³¿ù ÀÌ»ó);
COMORB14= h09_g9_1;
IF H09_G9_1 IN (1,2,3) THEN COMORB14=1; 

MISS_COMORB14=(COMORB14=.);
IF MISS_COMORB14=1 THEN DELETE;

/*IF h09_g9_1 IN (0,1) THEN COMORB=0;
ELSE IF h09_g9_1 IN (2,3) THEN COMORB=1;*/

* CES-D Score;
DES1=P0905_9-1; IF P0905_9 IN (9) THEN DES1=.;
DES2=4-P0905_10; IF P0905_10 IN (9) THEN DES2=.;
DES3=P0905_11-1; IF P0905_11 IN (9) THEN DES3=.;
DES4=P0905_12-1; IF P0905_12 IN (9) THEN DES4=.;
DES5=P0905_13-1; IF P0905_13 IN (9) THEN DES5=.;
DES6=P0905_14-1; IF P0905_14 IN (9) THEN DES6=.;
DES7=4-P0905_15; IF P0905_15 IN (9) THEN DES7=.;
DES8=P0905_16-1; IF P0905_16 IN (9) THEN DES8=.;
DES9=P0905_17-1; IF P0905_17 IN (9) THEN DES9=.;
DES10=P0905_18-1; IF P0905_18 IN (9) THEN DES10=.;
DES11=P0905_19-1; IF P0905_19 IN (9) THEN DES11=.;

TOTAL_DES14=(DES1+DES2+DES3+DES4+DES5+DES6+DES7+DES8+DES9+DES10+DES11);

* ¹æ °¹¼ö;
ROOM14=h0906_4;

* ÁýÀÇ °¡°Ý;
HOU_PRI14=h0906_6;

* Àå¾ÖÁ¾·ù;
IF h09_g8 IN (0) THEN DISAB14=0; ELSE DISAB14=1;

* û¼Ò³â;
IF AGE14<19 THEN CHILD=1; ELSE CHILD=0;

* Á¾´Ü¸é °¡ÁßÄ¡;
WEIGHT14=p09_wsl;

KEEP SEX14 hid h09_g3 H_PID h09_pid AGE14 agec h09_g4 AGEC TOTAL_A14 P0905_3AQ1 C_SMOK14 p0905_3aq5 SMOK14 AMOUNT14 p0905_3aq6 NO_TRIAL14 p0905_3aq7 NO_PLAN14 HARD14 P0905_3AQ9 
FM_SIZE14 h0901_1  h09_cin INC14 INC_DIST14 h09_hc MARR14 h09_g10 EDU14 h09_g6 SRH14 h09_med2 REGION14 h09_reg5  DRK14 p0905_2 JOB14 h09_eco4 HAPP14 p0903_12 COMORB14 h09_g9_1 WEIGHT14 p09_wsl 
SECOND_SMOK14 P0905_3AQ9 HEAVY_DRK14 p0905_4aq1 ECO h09_eco9 JOB14 TOTAL_DES14 SRH_SCORE14 HEAVY_AMT14 HAPP_SCORE14 HARD14_2 p0905_3 DRK_AMT14 METRO14 HV_DR14 RELI14 ROOM14 HOU_PRI14 DISAB14
CHILD;

RUN;

PROC SQL;
CREATE TABLE A.KWP9 AS
SELECT *,
COUNT(*) AS MEMBER14
FROM KWP9
GROUP BY HID;
RUN;

* 2015³â Çѱ¹º¹ÁöÆгΠÀÚ·á;

DATA KWP10; SET DATASET.Koweps_hpc10_2015_beta2;

HID=H10_ID;

* ¼ºº°, ID;
SEX15=h10_g3;
H_PID=h10_pid;

* ¿¬·É 19¼¼ ÀÌ»ó;
AGE15=2015-h10_g4;  

 * ÇöÀç Èí¿¬  ¿©ºÎ (1: ÇÇ¿ò, 2: ÇÇ¿ìÁö ¾ÊÀ½);
SMOK15=p1005_3aq5;
IF p1005_3aq5 IN (2) THEN SMOK15=0;
ELSE IF p1005_3aq5 IN (9) THEN SMOK15=.;

* ÇÏ·ç Æò±Õ Èí¿¬·®;
AMOUNT15=p1005_3aq6;
IF p1005_3aq6 IN (999) THEN AMOUNT15=.;

** 15°³ºñ ÀÌ»ó Heavy amount·Î Á¤ÀÇ;
IF AMOUNT15 >= 15 THEN HEAVY_AMT15=1; ELSE IF 0<AMOUNT15<15 THEN HEAVY_AMT15=0;

* ÃÖ±Ù 1³â°£ ±Ý¿¬ ½Ãµµ (1:¿¹, 2: ¾Æ´Ï¿À);
IF p1005_3aq7 IN (1) THEN NO_TRIAL15=0;
IF p1005_3aq7 IN (2) THEN NO_TRIAL15=1;
IF p1005_3aq7 IN (9) THEN NO_TRIAL15=.;

* ±Ý¿¬ °èȹ (1: 1°³¿ù ¾È, 2: 6°³¿ù ¾È, 3: ¾ðÁ¨°¡´Â ÀÖ´Ù, 4: ÇöÀç·Î¼­´Â ¾ø´Ù);
NO_PLAN15=p1005_3aq8;
IF p1005_3aq8 IN (4) THEN NO_PLAN15=1;
ELSE IF p1005_3aq8 IN (1,2,3) THEN NO_PLAN15=0;
ELSE IF p1005_3aq8 IN (9) THEN NO_PLAN15=.;

IF SMOK15=1 THEN DO;
IF HEAVY_AMT15=. OR NO_PLAN15=. OR NO_TRIAL15=. THEN DELETE;
END;

* Hardcore smoker Á¤ÀÇ;
IF HEAVY_AMT15 IN (1) & NO_TRIAL15 IN (1) & NO_PLAN15 IN (1) THEN HARD15=1; ELSE HARD15=0;
IF AMOUNT15>20 & NO_TRIAL15 IN (1) & NO_PLAN15 IN (1) THEN HARD15_2=1; ELSE HARD15_2=0;

IF SMOK15 IN (0) THEN DO;
HEAVY_AMT15=0; AMOUNT15=0; NO_PLAN15=0; NO_TRIAL15=0; 
END;

* ½Ç³» °ø°£¿¡¼­ ŸÀÎÀÇ ´ã¹è¿¬±â¸¦ ¸ÃÀº ½Ã°£ Á¤µµ (1: 0½Ã°£(¾øÀ½), 2: 1½Ã°£ ¹Ì¸¸, 3: 1½Ã°£ ÀÌ»ó);
IF P1005_3AQ9 IN (1) THEN SECOND_SMOK15=0; 
ELSE IF P1005_3AQ9 IN (2,3) THEN SECOND_SMOK15=1; 
*ELSE IF P1005_3AQ9 IN (3) THEN SECOND_SMOK15=2; 
* MISS_SECOND=(SECOND_SMOK15=.);
* 94¸í;
IF SECOND_SMOK15=. THEN DELETE;

* °¡±¸¿ø¼ö º¸Á¤ °æ»ó °¡±¸¼Òµæ;
FM_SIZE15=SQRT(h1001_1); 
INC15=(h10_cin)/FM_SIZE15;

MISS_INC15=(INC15=. OR INC15<=0);
IF MISS_INC15=1 THEN DELETE;

* Á¾±³;
RELI15=2-h10_g11;
IF RELI15 IN (0,1);

* ±ÕµîÈ­ ¼Òµæ¿¡ µû¸¥ °¡±¸±¸ºÐ(1: ÀϹݰ¡±¸, 2: Àú¼ÒµæÃþ °¡±¸);
INC_DIST15=h10_hc;

* È¥ÀÎ ¿©ºÎ(1: À¯¹è¿ì, 2: »çº°, 3: ÀÌÈ¥, 4: º°°Å, 5: ¹ÌÈ¥, 6:±âŸ);
IF h10_g10 IN (1) THEN MARR15=1; 
ELSE IF h10_g10 IN (2,3,4) THEN MARR15=2; 
ELSE IF h10_g10 IN (5,6) THEN MARR15=3; 

MISS_MARR15=(MARR15=.);
IF MISS_MARR15=1 THEN DELETE;

* ±³À°¼öÁØ;
IF h10_g6 IN (2:4) THEN EDU15=1;
ELSE IF h10_g6 IN (5) THEN EDU15=2;
ELSE IF h10_g6 IN (6:9) THEN EDU15=3;

MISS_EDU15=(EDU15=.);
IF MISS_EDU15=1 THEN DELETE;

* ÁÖ°üÀû °Ç°­¼öÁØ;
IF h10_med2 IN (1,2) THEN SRH15=1; ELSE IF h10_med2 IN (3,4,5) THEN SRH15=0; ELSE SRH15=.;
SRH_SCORE15= 6-h10_med2;

IF SRH_SCORE15=. THEN MISS_SRH_SCORE15=1;
IF SRH_SCORE15=. THEN DELETE; 

* 5°³ ±Ç¿ªº° Áö¿ª±¸ºÐ(1.¼­¿ï, 2. ±¤¿ª½Ã, 3.½Ã, 4.±º,5.µµ³óº¹ÇÕ±º), H_REG7: 7°³ ±Ç¿ªº° Áö¿ª±¸ºÐ(1.¼­¿ï, 2.¼öµµ±Ç(ÀÎõ/°æ±â), 3. ºÎ»ê/°æ³²/¿ï»ê, 4.´ë±¸/°æºÏ, 5. ´ëÀü/Ãæ³², 6. °­¿ø/ÃæºÏ, 7. ±¤ÁÖ/Àü³²/ÀüºÏ/Á¦ÁÖµµ;
 IF h10_reg5 IN (1,2) THEN REGION15=1; ELSE IF h10_reg5 IN (3) THEN REGION15=2; ELSE IF h10_reg5 IN (4,5) THEN REGION15=3;
 IF h10_reg5 IN (1,2) THEN METRO15=1; ELSE METRO15=0;

 IF REGION15=. THEN MISS_REGION15=1;
 IF MISS_REGION15=1 THEN DELETE;

* À½ÁÖ(1: ¿ù 1ȸ ÀÌÇÏ, 2: ¿ù 2-4ȸ, 3: ÁÖ 2~3ȸ, 4: ÁÖ 4ȸ ÀÌ»ó, 5: ÀüÇô ¸¶½ÃÁö ¾Ê´Â´Ù);
IF p1005_2 IN (1,2) THEN DRK15=2; 
ELSE IF p1005_2 IN (3,4) THEN DRK15=3;
ELSE IF p1005_2 IN (5) THEN DRK15=1;

MISS_DRK15=(DRK15=.);
IF MISS_DRK15=1 THEN DELETE; 

IF p1005_3 IN (1,2,3) THEN DRK_AMT15=1; 
ELSE IF p1005_3 IN (4,5) THEN DRK_AMT15=2;
ELSE IF p1005_3 IN (.,9) THEN DRK_AMT15=0;

* ÇÑ ¹ø¿¡ ¼úÁ¼®¿¡¼­ 6ÀÜ ÀÌ»ó ¸¶½Ã´Â °æ¿ì;
HEAVY_DRK15=p1005_4aq1;
IF p1005_4aq1 IN (2,3,4) THEN HEAVY_DRK15=2;
IF p1005_4aq1 IN (5) THEN HEAVY_DRK15=3;
IF p1005_2 IN (5) THEN HEAVY_DRK15=1;

IF p1005_4aq1 IN (5) THEN HV_DR15=1; ELSE HV_DR15=0;

MISS_HEAVY_DRK15=(HEAVY_DRK15=.);
IF MISS_HEAVY_DRK15=1 THEN DELETE; 

* Àü¹ÝÀû ¸¸Á·µµ;
IF p1003_12 IN (1,2) THEN HAPP15=1;
ELSE IF p1003_12 IN (3) THEN HAPP15=2;
ELSE IF p1003_12 IN (4,5) THEN HAPP15=3; 

HAPP_SCORE15=p1003_12;

MISS_HAPP15=(HAPP15=.);
IF MISS_HAPP15=1 THEN DELETE; 

* µ¿¹ÝÁúȯ (0: ºñÇØ´ç, 1: 3°³¿ù ¹Ì¸¸, 2: 3-6°³¿ù, 3: 6°³¿ù ÀÌ»ó);
COMORB15=h10_g9_1;
IF H10_G9_1 IN (1,2,3) THEN COMORB15=1; 

MISS_COMORB15=(COMORB15=.);
IF MISS_COMORB15=1 THEN DELETE;

/*IF h09_g9_1 IN (0,1) THEN COMORB=0;
ELSE IF h09_g9_1 IN (2,3) THEN COMORB=1;*/

* Á÷¾÷ ºÐ·ù;
ECO9=SUBSTR(PUT(h10_eco9,8.),5,2);
ECO=ECO9+0;
/*IF ECO IN (1:3) THEN JOB15=1;
ELSE IF ECO IN (4:9) THEN JOB15=2;
* ELSE IF ECO IN (6:9) THEN JOB15=3;
ELSE IF ECO IN (10) THEN JOB15=3;
ELSE IF H10_ECO9 = . THEN JOB15=3;*/

IF ECO IN (1:3) THEN JOB15=1;
ELSE IF ECO IN (4:5) THEN JOB15=2;
ELSE IF ECO IN (6:9) THEN JOB15=3;
ELSE IF ECO IN (10) THEN JOB15=4;
ELSE IF H10_ECO9 = . THEN JOB15=4;

MISS_JOB15=(JOB15=.);
IF MISS_JOB15=1 THEN DELETE; 

* CES-D Score;
DES1=P1005_9-1; IF P1005_9 IN (9) THEN DES1=.;
DES2=4-P1005_10; IF P1005_10 IN (9) THEN DES2=.;
DES3=P1005_11-1; IF P1005_11 IN (9) THEN DES3=.;
DES4=P1005_12-1; IF P1005_12 IN (9) THEN DES4=.;
DES5=P1005_13-1; IF P1005_13 IN (9) THEN DES5=.;
DES6=P1005_14-1; IF P1005_14 IN (9) THEN DES6=.;
DES7=4-P1005_15; IF P1005_15 IN (9) THEN DES7=.;
DES8=P1005_16-1; IF P1005_16 IN (9) THEN DES8=.;
DES9=P1005_17-1; IF P1005_17 IN (9) THEN DES9=.;
DES10=P1005_18-1; IF P1005_18 IN (9) THEN DES10=.;
DES11=P1005_19-1; IF P1005_19 IN (9) THEN DES11=.;

TOTAL_DES15=(DES1+DES2+DES3+DES4+DES5+DES6+DES7+DES8+DES9+DES10+DES11);
 
* Á¾´Ü¸é °¡ÁßÄ¡;
WEIGHT15=p10_wsl;

* ¹æ °¹¼ö;
ROOM15=h1006_4;

* ÁýÀÇ °¡°Ý;
HOU_PRI15=h1006_6;

* Àå¾ÖÁ¾·ù;
IF h10_g8 IN (0) THEN DISAB15=0; ELSE DISAB15=1;

* û¼Ò³â;
IF AGE15<19 THEN CHILD=1; ELSE CHILD=0;

KEEP hid SEX15 H_PID AGE15 SMOK15 AMOUNT15 p1005_3aq6 HEAVY_AMT15 NO_TRIAL15 p1005_3aq7 NO_PLAN15 p1005_3aq8 HARD15 FM_SIZE15 h1001_1 h10_cin FM_SIZE15 INC15 INC_DIST15  h10_hc MARR15  h10_g10
EDU15  h10_g6  SRH15  h10_med2 REGION15 h10_reg5 DRK15 p1005_2 JOB15 h10_eco4 HAPP15 p1003_12 COMORB15 h10_g9_1 WEIGHT15 p10_wsl SECOND_SMOK15 P1005_3AQ9 HEAVY_DRK15 p1005_4aq1 ECO h10_eco9 JOB15
TOTAL_DES15 SRH_SCORE15 HAPP_SCORE15 HARD15_2 DRK_AMT15 p1005_3 METRO15 HV_DR15 RELI15 ROOM15 HOU_PRI15 DISAB15 CHILD;

RUN;

PROC SQL;
CREATE TABLE A.KWP10 AS
SELECT *,
COUNT(*) AS MEMBER15
FROM KWP10
GROUP BY HID;
RUN;


PROC SORT DATA=A.KWP9; BY H_PID; PROC SORT DATA=A.KWP10; BY H_PID; RUN;
DATA A.KWP910; MERGE A.KWP9 A.KWP10; BY H_PID; IF AGE14=. OR AGE15=. THEN DELETE; 
DIFF_SMOK=SMOK14-SMOK15;
DIFF_AMT=AMOUNT14-AMOUNT15;
DIFF_HEAVY_AMT=HEAVY_AMT14-HEAVY_AMT15;
DIFF_NO_TRIAL=NO_TRIAL14-NO_TRIAL15;
DIFF_NO_PLAN=NO_PLAN14-NO_PLAN15;

%MACRO YEAR(Y=);
%MACRO RES(A=); 
IF EDU&Y. IN (&A.) THEN EDU&Y._&A.=1; ELSE EDU&Y._&A.=0;
IF JOB&Y. IN (&A.) THEN JOB&Y._&A.=1; ELSE JOB&Y._&A.=0;
IF REGION&Y. IN (&A.) THEN REGION&Y._&A.=1; ELSE REGION&Y._&A.=0;
IF MARR&Y. IN (&A.) THEN MARR&Y._&A.=1; ELSE MARR&Y._&A.=0;
IF DRK&Y. IN (&A.) THEN DRK&Y._&A.=1; ELSE DRK&Y._&A.=0;
IF HEAVY_DRK&Y. IN (&A.) THEN HEAVY_DRK&Y._&A.=1; ELSE HEAVY_DRK&Y._&A.=0;
%MEND;
%RES(A=1); %RES(A=2);%RES(A=3); 
%MEND;
%YEAR(Y=14); %YEAR(Y=15);

RUN;

PROC SQL;
CREATE TABLE KWP910_NEW AS
SELECT *,
CASE WHEN YR5_SMOK=1 OR HIST_DUR_YR>=5 THEN 1 ELSE 0 
END AS YEAR5 
FROM A.KWP910 AS A LEFT JOIN A.INFO_SUM_SMOK AS B
ON A.H_PID=B.H_PID2
WHERE B.HIST_START^=.;
QUIT;

DATA KWP910_NEW; SET KWP910_NEW; 
IF HEAVY_AMT14 IN (1) & NO_TRIAL14 IN (1) & NOPL IN (1) THEN HARD14=1; ELSE HARD14=0;
IF AMOUNT14>20 & NO_TRIAL14 IN (1) & NOPL IN (1) THEN HARD14_2=1; ELSE HARD14_2=0;
RUN;

PROC SORT DATA=KWP910_NEW; BY HID; PROC SORT DATA=A.KWP910_CHILD; BY HID; 
DATA A.KWP910_NEW; MERGE KWP910_NEW A.KWP910_CHILD; BY HID; IF SMOK14=1; RUN;

* STATA DATASET;
PROC EXPORT DATA= A.KWP910_NEW
            OUTFILE= "C:\Users\Ikhan Kim\Dropbox\´ëÇпø °ü·Ã\2017³â 2Çбâ\ÀÇ·á°ü¸®Çйæ¹ý¼¼¹Ì³ª\Term paper ÀÛ¼º\Data\hardening.dta" 
            DBMS=STATA REPLACE;
RUN;

/* PROC SORT DATA=TEMP; BY SEX AGEC;
PROC RANK DATA=TEMP OUT=A.KWP9 GROUPS=4 TIES=MEAN; VAR INC; RANKS INC_RANK; BY SEX AGEC; RUN; */  

* 2016³â Çѱ¹º¹ÁöÆгΠÀÚ·á;

DATA KWP11; SET DATASET.Koweps_hpwc11_2016_beta1;

HID=H11_ID;

* ¼ºº°, ID;
SEX16=h11_g3;
H_PID=h11_pid;

* ¿¬·É 19¼¼ ÀÌ»ó;
AGE16=2016-h11_g4;  

 * ÇöÀç Èí¿¬  ¿©ºÎ (1: ÇÇ¿ò, 2: ÇÇ¿ìÁö ¾ÊÀ½);
SMOK16=p1105_3aq5;
IF p1105_3aq5 IN (2) THEN SMOK16=0;
ELSE IF p1105_3aq5 IN (9) THEN SMOK16=.;

* ÇÏ·ç Æò±Õ Èí¿¬·®;
AMOUNT16=p1105_3aq6;
IF p1105_3aq6 IN (999) THEN AMOUNT16=.;

** 15°³ºñ ÀÌ»ó Heavy amount·Î Á¤ÀÇ;
IF AMOUNT16 >= 15 THEN HEAVY_AMT16=1; ELSE IF 0<AMOUNT16<15 THEN HEAVY_AMT16=0;

* ÃÖ±Ù 1³â°£ ±Ý¿¬ ½Ãµµ (1:¿¹, 2: ¾Æ´Ï¿À);
IF p1105_3aq7 IN (1) THEN NO_TRIAL16=0;
IF p1105_3aq7 IN (2) THEN NO_TRIAL16=1;
IF p1105_3aq7 IN (9) THEN NO_TRIAL16=.;

* ±Ý¿¬ °èȹ (1: 1°³¿ù ¾È, 2: 6°³¿ù ¾È, 3: ¾ðÁ¨°¡´Â ÀÖ´Ù, 4: ÇöÀç·Î¼­´Â ¾ø´Ù);
NO_PLAN16=p1105_3aq8;
IF p1105_3aq8 IN (4) THEN NO_PLAN16=1;
ELSE IF p1105_3aq8 IN (1,2,3) THEN NO_PLAN16=0;
ELSE IF p1105_3aq8 IN (9) THEN NO_PLAN16=.;

IF SMOK16=1 THEN DO;
IF HEAVY_AMT16=. OR NO_PLAN16=. OR NO_TRIAL16=. THEN DELETE;
END;

* Hardcore smoker Á¤ÀÇ;
IF HEAVY_AMT16 IN (1) & NO_TRIAL16 IN (1) & NO_PLAN16 IN (1) THEN HARD16=1; ELSE HARD16=0;
IF AMOUNT16>20 & NO_TRIAL16 IN (1) & NO_PLAN16 IN (1) THEN HARD16_2=1; ELSE HARD16_2=0;

IF SMOK16 IN (0) THEN DO;
HEAVY_AMT16=0; AMOUNT16=0; NO_PLAN16=0; NO_TRIAL16=0; 
END;

* ½Ç³» °ø°£¿¡¼­ ŸÀÎÀÇ ´ã¹è¿¬±â¸¦ ¸ÃÀº ½Ã°£ Á¤µµ (1: 0½Ã°£(¾øÀ½), 2: 1½Ã°£ ¹Ì¸¸, 3: 1½Ã°£ ÀÌ»ó);
IF P1105_3AQ9 IN (1) THEN SECOND_SMOK16=0; 
ELSE IF P1105_3AQ9 IN (2,3) THEN SECOND_SMOK16=1; 
* ELSE IF P1105_3AQ9 IN (3) THEN SECOND_SMOK16=2; 
* MISS_SECOND=(SECOND_SMOK16=.);
* 94¸í;
IF SECOND_SMOK16=. THEN DELETE;

* °¡±¸¿ø¼ö º¸Á¤ °æ»ó °¡±¸¼Òµæ;
FM_SIZE16=SQRT(h1101_1); 
INC16=(h11_cin)/FM_SIZE16;

MISS_INC16=(INC16=. OR INC16<=0);
IF MISS_INC16=1 THEN DELETE;

* Á¾±³;
RELI16=2-h11_g11;
IF RELI16 IN (0,1);

* ±ÕµîÈ­ ¼Òµæ¿¡ µû¸¥ °¡±¸±¸ºÐ(1: ÀϹݰ¡±¸, 2: Àú¼ÒµæÃþ °¡±¸);
INC_DIST16=h11_hc;

* È¥ÀÎ ¿©ºÎ(1: À¯¹è¿ì, 2: »çº°, 3: ÀÌÈ¥, 4: º°°Å, 5: ¹ÌÈ¥, 6:±âŸ);
IF h11_g10 IN (1) THEN MARR16=1; 
ELSE IF h11_g10 IN (2,3,4) THEN MARR16=2; 
ELSE IF h11_g10 IN (5,6) THEN MARR16=3; 

MISS_MARR16=(MARR16=.);
IF MISS_MARR16=1 THEN DELETE;

* ±³À°¼öÁØ;
IF h11_g6 IN (2:4) THEN EDU16=1;
ELSE IF h11_g6 IN (5) THEN EDU16=2;
ELSE IF h11_g6 IN (6:9) THEN EDU16=3;

MISS_EDU16=(EDU16=.);
IF MISS_EDU16=1 THEN DELETE;

* ÁÖ°üÀû °Ç°­¼öÁØ;
IF h11_med2 IN (1,2) THEN SRH16=1; ELSE IF h11_med2 IN (3,4,5) THEN SRH16=0; ELSE SRH16=.;
SRH_SCORE16= 6-h11_med2;

IF SRH_SCORE16=. THEN MISS_SRH_SCORE16=1;
IF SRH_SCORE16=. THEN DELETE; 

* 5°³ ±Ç¿ªº° Áö¿ª±¸ºÐ(1.¼­¿ï, 2. ±¤¿ª½Ã, 3.½Ã, 4.±º,5.µµ³óº¹ÇÕ±º), H_REG7: 7°³ ±Ç¿ªº° Áö¿ª±¸ºÐ(1.¼­¿ï, 2.¼öµµ±Ç(ÀÎõ/°æ±â), 3. ºÎ»ê/°æ³²/¿ï»ê, 4.´ë±¸/°æºÏ, 5. ´ëÀü/Ãæ³², 6. °­¿ø/ÃæºÏ, 7. ±¤ÁÖ/Àü³²/ÀüºÏ/Á¦ÁÖµµ;
 IF h11_reg5 IN (1,2) THEN REGION16=1; ELSE IF h11_reg5 IN (3) THEN REGION16=2; ELSE IF h11_reg5 IN (4,5) THEN REGION16=3;
 IF h11_reg5 IN (1,2) THEN METRO16=1; ELSE METRO16=0; 

 IF REGION16=. THEN MISS_REGION16=1;
 IF MISS_REGION16=1 THEN DELETE;

 * À½ÁÖ(1: ¿ù 1ȸ ÀÌÇÏ, 2: ¿ù 2-4ȸ, 3: ÁÖ 2~3ȸ, 4: ÁÖ 4ȸ ÀÌ»ó, 5: ÀüÇô ¸¶½ÃÁö ¾Ê´Â´Ù);
IF p1105_2 IN (1,2) THEN DRK16=2; 
ELSE IF p1105_2 IN (3,4) THEN DRK16=3;
ELSE IF p1105_2 IN (5) THEN DRK16=1;

MISS_DRK16=(DRK16=.);
IF MISS_DRK16=1 THEN DELETE; 

IF p1105_3 IN (1,2,3) THEN DRK_AMT16=1; 
ELSE IF p1105_3 IN (4,5) THEN DRK_AMT16=2;
ELSE IF p1105_3 IN (.,9) THEN DRK_AMT16=0;

* ÇÑ ¹ø¿¡ ¼úÁ¼®¿¡¼­ 6ÀÜ ÀÌ»ó ¸¶½Ã´Â °æ¿ì "1. ÀüÇô¾ø´Ù  2. ¸î ´Þ¿¡ Çѹø Á¤µµ 3. ÇÑ´Þ¿¡ Çѵιø Á¤µµ  4. ÀÏÁÖÀÏ¿¡ Çѵιø Á¤µµ  5. °ÅÀÇ ¸ÅÀÏ";

HEAVY_DRK16=p1105_4aq1;
IF p1105_4aq1 IN (2,3,4) THEN HEAVY_DRK16=2;
IF p1105_4aq1 IN (5) THEN HEAVY_DRK16=3;
IF p1105_2 IN (5) THEN HEAVY_DRK16=1;

IF p1105_4aq1  IN (5) THEN HV_DR16=1; ELSE HV_DR16=0;

MISS_HEAVY_DRK16=(HEAVY_DRK16=.);
IF MISS_HEAVY_DRK16=1 THEN DELETE; 


* Àü¹ÝÀû ¸¸Á·µµ 1.¸Å¿ìºÒ¸¸Á·    2.´ëü·Î ºÒ¸¸Á·   3.±×Àú±×·¸´Ù  4.´ëü·Î ¸¸Á·  5.¸Å¿ì¸¸Á·; 
IF p1103_12 IN (1,2) THEN HAPP16=3;
ELSE IF p1103_12 IN (3) THEN HAPP16=2;
ELSE IF p1103_12 IN (4,5) THEN HAPP16=1; 

HAPP_SCORE16=p1103_12;

MISS_HAPP16=(HAPP16=.);
IF MISS_HAPP16=1 THEN DELETE; 

* µ¿¹ÝÁúȯ (0: ºñÇØ´ç, 1: 3°³¿ù ¹Ì¸¸, 2: 3-6°³¿ù, 3: 6°³¿ù ÀÌ»ó);
COMORB16=h11_g9_1;
IF H11_G9_1 IN (1,2,3) THEN COMORB16=1; 

MISS_COMORB16=(COMORB16=.);
IF MISS_COMORB16=1 THEN DELETE;

/*IF h09_g9_1 IN (0,1) THEN COMORB=0;
ELSE IF h09_g9_1 IN (2,3) THEN COMORB=1;*/

* Á÷¾÷ ºÐ·ù;
ECO9=SUBSTR(PUT(h11_eco9,8.),5,2);
ECO=ECO9+0;
/*IF ECO IN (1:3) THEN JOB16=1;
ELSE IF ECO IN (4:9) THEN JOB16=2;
*ELSE IF ECO IN (6:9) THEN JOB16=3;
ELSE IF ECO IN (10) THEN JOB16=3;
ELSE IF H11_ECO9 = . THEN JOB16=3;*/

IF ECO IN (1:3) THEN JOB16=1;
ELSE IF ECO IN (4:5) THEN JOB16=2;
ELSE IF ECO IN (6:9) THEN JOB16=3;
ELSE IF ECO IN (10) THEN JOB16=4;
ELSE IF H11_ECO9 = . THEN JOB16=4;

MISS_JOB16=(JOB16=.);
IF MISS_JOB16=1 THEN DELETE;


* CES-D Score;
DES1=P1105_9-1; IF P1105_9 IN (9) THEN DES1=.;
DES2=4-P1105_10; IF P1105_10 IN (9) THEN DES2=.;
DES3=P1105_11-1; IF P1105_11 IN (9) THEN DES3=.;
DES4=P1105_12-1; IF P1105_12 IN (9) THEN DES4=.;
DES5=P1105_13-1; IF P1105_13 IN (9) THEN DES5=.;
DES6=P1105_14-1; IF P1105_14 IN (9) THEN DES6=.;
DES7=4-P1105_15; IF P1105_15 IN (9) THEN DES7=.;
DES8=P1105_16-1; IF P1105_16 IN (9) THEN DES8=.;
DES9=P1105_17-1; IF P1105_17 IN (9) THEN DES9=.;
DES10=P1105_18-1; IF P1105_18 IN (9) THEN DES10=.;
DES11=P1105_19-1; IF P1105_19 IN (9) THEN DES11=.;

TOTAL_DES16=(DES1+DES2+DES3+DES4+DES5+DES6+DES7+DES8+DES9+DES10+DES11);
 
* Á¾´Ü¸é °¡ÁßÄ¡;
WEIGHT16=p11_wsl;

* ¹æ °¹¼ö;
ROOM16=h1106_4;

* ÁýÀÇ °¡°Ý;
HOU_PRI16=h1106_6;

* Àå¾ÖÁ¾·ù;
IF h11_g8 IN (0) THEN DISAB16=0; ELSE DISAB16=1;

* û¼Ò³â;
IF AGE16<19 THEN CHILD=1; ELSE CHILD=0;

KEEP SEX16 hid H_PID AGE16 SMOK16 AMOUNT16 p1105_3aq6 HEAVY_AMT16 NO_TRIAL16 p1105_3aq7 NO_PLAN16 p1105_3aq8 HARD16 FM_SIZE16 h1101_1 h11_cin FM_SIZE16 INC16 INC_DIST16  h11_hc MARR16  h11_g10
EDU16  h11_g6  SRH16  h11_med2 REGION16 h11_reg5 DRK16 p1105_2 JOB16 h11_eco4 HAPP16 p1103_12 COMORB16 h11_g9_1 WEIGHT16 p11_wsl SECOND_SMOK16 P1105_3AQ9 HEAVY_DRK16 p1105_4aq1 ECO h11_eco9 JOB16
TOTAL_DES16 SRH_SCORE16 p1105_3aq2 HAPP_SCORE16 HARD16_2 p1105_3 DRK_AMT16 METRO16 HV_DR16 RELI16 ROOM16 HOU_PRI16 DISAB16 CHILD;

RUN;

PROC SQL;
CREATE TABLE A.KWP11 AS
SELECT *,
COUNT(*) AS MEMBER16
FROM KWP11
GROUP BY HID;
RUN;

PROC SORT DATA=A.KWP9; BY H_PID; PROC SORT DATA=A.KWP10; BY H_PID; RUN; PROC SORT DATA=A.KWP11; BY H_PID; RUN;
DATA A.KWP91011; MERGE A.KWP9 A.KWP10 A.KWP11; BY H_PID; IF AGE14=. OR AGE15=. OR AGE16 = . THEN DELETE; 
DIFF_SMOK=SMOK14-SMOK16;
DIFF_AMT=AMOUNT14-AMOUNT16;
DIFF_HEAVY_AMT=HEAVY_AMT14-HEAVY_AMT16;
DIFF_NO_TRIAL=NO_TRIAL14-NO_TRIAL16;
DIFF_NO_PLAN=NO_PLAN14-NO_PLAN16;

%MACRO YEAR(Y=);
%MACRO RES(A=); 
IF EDU&Y. IN (&A.) THEN EDU&Y._&A.=1; ELSE EDU&Y._&A.=0;
IF JOB&Y. IN (&A.) THEN JOB&Y._&A.=1; ELSE JOB&Y._&A.=0;
IF REGION&Y. IN (&A.) THEN REGION&Y._&A.=1; ELSE REGION&Y._&A.=0;
IF MARR&Y. IN (&A.) THEN MARR&Y._&A.=1; ELSE MARR&Y._&A.=0;
IF DRK&Y. IN (&A.) THEN DRK&Y._&A.=1; ELSE DRK&Y._&A.=0;
IF HEAVY_DRK&Y. IN (&A.) THEN HEAVY_DRK&Y._&A.=1; ELSE HEAVY_DRK&Y._&A.=0;
%MEND;
%RES(A=1); %RES(A=2);%RES(A=3); 
%MEND;
%YEAR(Y=14); %YEAR(Y=15);%YEAR(Y=16);

RUN;

PROC SQL;
CREATE TABLE KWP91011_NEW AS
SELECT *,
CASE WHEN YR5_SMOK=1 OR HIST_DUR_YR>=5 THEN 1 ELSE 0 
END AS YEAR5 
FROM A.KWP91011 AS A LEFT JOIN A.INFO_SUM_SMOK AS B
ON A.H_PID=B.H_PID2
WHERE B.HIST_START^=.;
QUIT;

DATA KWP91011_NEW; SET KWP91011_NEW; 
IF HEAVY_AMT14 IN (1) & NO_TRIAL14 IN (1) & NOPL IN (1) THEN HARD14=1; ELSE HARD14=0;
IF AMOUNT14>20 & NO_TRIAL14 IN (1) & NOPL IN (1) THEN HARD14_2=1; ELSE HARD14_2=0;
RUN;

PROC SORT DATA=KWP91011_NEW; BY HID; PROC SORT DATA=A.KWP91011_CHILD; BY HID; 
DATA A.KWP91011_NEW; MERGE KWP91011_NEW A.KWP91011_CHILD; BY HID; IF SMOK14=1; RUN;

* STATA DATASET;
PROC EXPORT DATA= A.KWP91011_NEW 
            OUTFILE= "C:\Users\Ikhan Kim\Dropbox\´ëÇпø °ü·Ã\2017³â 2Çбâ\ÀÇ·á°ü¸®Çйæ¹ý¼¼¹Ì³ª\Term paper ÀÛ¼º\Data\hardening_panel2.dta" 
            DBMS=STATA REPLACE;
RUN;

* ´ã¹è¸¦ óÀ½ ÇÇ¿î ³ªÀÌ, Æò»ý Èí¿¬·®, ±â°£ µî Á¤º¸;
/* PROC CONTENTS DATA=DATASET.Koweps_hp01_11_long_170331; RUN; */

DATA TEMP; SET DATASET.Koweps_hp01_11_long_170331; KEEP H_PID wv P05_3AQ1 P05_3AQ2 P05_3AQ3 P05_3AQ4; IF P05_3AQ1=. THEN DELETE; RUN;
PROC SORT DATA=TEMP; BY H_PID P05_3AQ1 DESCENDING WV; RUN;
PROC SORT DATA=TEMP NODUPKEY; BY H_PID; RUN;

DATA A.INFO_SMK; SET TEMP; WV_INFO=WV; 
H_PID2=H_PID;
HIST_AMT=P05_3AQ1; HIST_START=P05_3AQ2; HIST_DUR_YR=P05_3AQ3; HIST_DUR_MT=P05_3AQ4; 
IF HIST_START<20 THEN START_C=1;
ELSE IF 20<=HIST_START<30 THEN START_C=2;
ELSE IF 30<=HIST_START<40 THEN START_C=3;
ELSE IF 40<=HIST_START<50 THEN START_C=4;
ELSE IF 50<=HIST_START THEN START_C=5;

KEEP H_PID2 WV_INFO HIST_AMT HIST_START HIST_DUR_YR HIST_DUR_MT START_C; RUN;

* 5³â °è»ê;
PROC CONTENTS DATA= DATASET.Koweps_hp01_11_long_170331; RUN;

DATA TEMP; SET DATASET.Koweps_hp01_11_long_170331; 
SMOK=p05_3aq5;
IF p05_3aq5 IN (2) THEN SMOK=0;
ELSE IF p05_3aq5 IN (.,9) THEN SMOK=.;
IF WV>=10 THEN DELETE;
KEEP H_PID WV p05_3aq5 SMOK; RUN;

PROC SQL;
CREATE TABLE TEMP2 AS
SELECT *,
SUM(SMOK) AS SMOK_SUM
FROM TEMP
GROUP BY H_PID;
QUIT;

DATA SMOK_SUM; SET TEMP2; IF SMOK_SUM=. THEN SMOK_SUM=0; 
IF SMOK_SUM>=5 THEN YR5_SMOK=1; ELSE YR5_SMOK=0; 
KEEP H_PID SMOK_SUM YR5_SMOK;
RUN;

PROC SORT DATA=SMOK_SUM OUT=A.SMOK_SUM NODUPKEY; BY H_PID; RUN;

* INFO¿Í SUM Á¤º¸ ÇÕÄ¡±â;
DATA INFO_SMK; SET A.INFO_SMK; H_PID=H_PID2; RUN;
PROC SORT DATA=A.SMOK_SUM; BY H_PID; PROC SORT DATA=INFO_SMK; BY H_PID; RUN; PROC SORT DATA=A.HARD1; BY H_PID; RUN;
DATA A.INFO_SUM_SMOK; MERGE A.SMOK_SUM INFO_SMK A.HARD1; BY H_PID; 
H_PID2=H_PID; DROP H_PID;
IF NOPL IN (0,1);
RUN;

PROC FREQ DATA=A.KWP910_NEW; TABLES HIST_START; RUN;
PROC FREQ DATA=A.KWP91011_NEW; TABLES sex14 age14 inc14 marr14 edu14 region14 drk14 comorb14 happ14 job14 second_smok14 heavy_drk14 inc15 marr15 edu15 region15 drk15 comorb15 happ15 job15 second_smok15 heavy_drk15
inc16 marr16 edu16 region16 drk16 comorb16 happ16 job16 second_smok16 heavy_drk16 HIST_START; RUN;

PROC FREQ DATA=A.KWP91011; TABLES no_plan14 no_trial16 no_plan16 no_trial16; RUN;

* Table 1;
PROC SORT DATA=A.KWP910_NEW; BY HARD14;

PROC FREQ DATA=A.KWP910_NEW; TABLES HARD14; RUN;

PROC FREQ DATA=A.KWP910_NEW; TABLES HEAVY_AMT14 NO_TRIAL14 NO_PLAN14; ODS OUTPUT ONEWAYFREQS=T1_1; RUN;
PROC FREQ DATA=A.KWP910_NEW; TABLES HEAVY_AMT14 NO_TRIAL14 NO_PLAN14; BY HARD14; ODS OUTPUT ONEWAYFREQS=T1_2; RUN;

PROC FREQ DATA=A.KWP910_NEW; TABLES HARD14 * (HEAVY_AMT14 NO_TRIAL14 NO_PLAN14)/CHISQ; RUN; 
PROC MEANS DATA=A.KWP910_NEW; VAR AMOUNT14 AGE14 SRH_SCORE14 HAPP_SCORE14 HIST_START; RUN;

PROC MEANS DATA=A.KWP910_NEW; VAR AMOUNT14 HIST_START age14; BY HARD14; ods output summary=t1_5; RUN;
PROC MEANS DATA=A.KWP910_NEW; VAR AMOUNT14 HIST_START age14; ods output summary=t1_6; RUN;
PROC TTEST DATA=A.KWP910_NEW; VAR AMOUNT14 HIST_START age14; CLASS HARD14; RUN;

PROC FREQ DATA=A.KWP910_NEW; TABLES sex14 edu14 job14 metro14 marr14 child_home14 second_smok14 hv_dr14 srh14 disab14 ;ODS OUTPUT ONEWAYFREQS=T1_3; RUN;
PROC FREQ DATA=A.KWP910_NEW; TABLES sex14 edu14 job14 metro14 marr14 child_home14 second_smok14 hv_dr14 srh14 disab14 ; BY HARD14; ODS OUTPUT ONEWAYFREQS=T1_4; RUN;

PROC FREQ DATA=A.KWP910_NEW; TABLES HARD14*(sex14 edu14 job14 metro14 marr14 child_home14 second_smok14 hv_dr14 srh14 disab14)/CHISQ ; ODS OUTPUT CHISQ=T1_7; RUN;

PROC SURVEYFREQ DATA=DATA1; WEIGHT WEIGHT; TABLES HARD14 * (fem age14 edu14_1 edu14_2 edu14_3 
job14_1 job14_2 job14_3 region14_1 region14_2 region14_3 marr14_1 marr14_2 marr14_3 
second_smok14 drk14_1 drk14_2 drk14_3  heavy_drk14_1 heavy_drk14_2 heavy_drk14_3 
comorb14 job15_1 job15_2 job15_3 region15_1 region15_2 region15_3 marr15_1 marr15_2 marr15_3 
second_smok15 drk15_1 drk15_2 drk15_3  heavy_drk15_1 heavy_drk15_2 heavy_drk15_3 
 comorb15) /CHISQ; ods output chisq=r1; RUN;

 PROC SURVEYFREQ DATA=DATA2; WEIGHT WEIGHT; TABLES HARD14 * (fem age14 edu14_1 edu14_2 edu14_3 
job14_1 job14_2 job14_3 region14_1 region14_2 region14_3 marr14_1 marr14_2 marr14_3 
second_smok14 drk14_1 drk14_2 drk14_3  heavy_drk14_1 heavy_drk14_2 heavy_drk14_3 
comorb14 job15_1 job15_2 job15_3 region15_1 region15_2 region15_3 marr15_1 marr15_2 marr15_3 
second_smok15 drk15_1 drk15_2 drk15_3  heavy_drk15_1 heavy_drk15_2 heavy_drk15_3 
 comorb15 job16_1 job16_2 job16_3  region16_1 region16_2 region16_3 marr16_1 marr16_2 marr16_3
second_smok16 drk16_1 drk16_2 drk16_3  heavy_drk16_1 heavy_drk16_2 heavy_drk16_3 
comorb16) /CHISQ; ods output chisq=r2; RUN;

proc ttest data=data1; WEIGHT WEIGHT; VAR AGE14  log_inc14 srh_score14 happ_score14  log_inc15 srh_score15 happ_score15 ; ods output ttests=t1; run;
proc ttest data=data2; WEIGHT WEIGHT; VAR AGE14  log_inc14 srh_score14 happ_score14  log_inc15 srh_score15 happ_score15  log_inc16 srh_score16 happ_score16; ods output ttests=t2; run;

* Appendix 1;
PROC FREQ DATA=A.KWP910_NEW; TABLES HARD14 * (SMOK15 HARD15); RUN;
PROC FREQ DATA=A.KWP91011_NEW; TABLES HARD14 * (SMOK15 SMOK16); ODS OUTPU CROSSTABFREQS=A1_1; RUN;

PROC FREQ DATA=A.KWP910_NEW; TABLES HARD14 * (HEAVY_AMT15 NO_TRIAL15 NO_PLAN15); ODS OUTPUT CROSSTABFREQS=A2_1; RUN;
PROC FREQ DATA=A.KWP91011_NEW; TABLES HARD14 * (HEAVY_AMT15 NO_TRIAL15 NO_PLAN15 HEAVY_AMT16 NO_TRIAL16 NO_PLAN16);  ODS OUTPUT CROSSTABFREQS=A2_2; RUN;

* Table 4;
DATA TEMP; SET DATA1; KEEP H_PID _WEIGHT HARD14 SMOK14 SMOK15 AMOUNT14 AMOUNT15 HEAVY_AMT14 HEAVY_AMT15 NO_PLAN14 NO_PLAN15 NO_TRIAL14 NO_TRIAL15
; IF HARD14=1 THEN _WEIGHT=1; IF _WEIGHT>0;RUN;
DATA TEMP2; SET A.HARD_PREV; IF YEAR1 IN (2013); RUN;

PROC SORT DATA=TEMP; BY H_PID; RUN; PROC SORT DATA=TEMP2; BY H_PID; RUN;

DATA TEMP3; MERGE TEMP2 TEMP; BY H_PID; IF HARD14 IN (0,1); IF YEAR1 IN (2013); RUN;

PROC SORT DATA=TEMP3; BY HARD14;

PROC SURVEYFREQ DATA=TEMP3; WEIGHT _WEIGHT; TABLES SMOK HEAVY_AMT NO_TRIAL NO_PLAN SMOK14 SMOK15 SMOK16 AMOUNT14 AMOUNT15 HEAVY_AMT14 HEAVY_AMT15 NO_PLAN14 NO_PLAN15 NO_TRIAL14 NO_TRIAL15; BY HARD14; ODS OUTPUT ONEWAY=F2_1; RUN; 
PROC SURVEYMEANS DATA=TEMP3; WEIGHT _WEIGHT; VAR AMOUNT AMOUNT14 AMOUNT15; BY HARD14; RUN;


DATA TEMP; SET DATA2; KEEP H_PID _WEIGHT HARD14 SMOK14 SMOK15 SMOK16 AMOUNT14 AMOUNT15 AMOUNT16 HEAVY_AMT14 HEAVY_AMT15 HEAVY_AMT16 NO_PLAN14 NO_PLAN15 NO_PLAN16 NO_TRIAL14 NO_TRIAL15 NO_TRIAL16
; IF HARD14=1 THEN _WEIGHT=1; IF _WEIGHT>0;RUN;
DATA TEMP2; SET A.HARD_PREV; IF YEAR1 IN (2013); RUN;

PROC SORT DATA=TEMP; BY H_PID; RUN; PROC SORT DATA=TEMP2; BY H_PID; RUN;

DATA TEMP3; MERGE TEMP2 TEMP; BY H_PID; IF HARD14 IN (0,1); IF YEAR1 IN (2013); RUN;

PROC SORT DATA=TEMP3; BY HARD14;

PROC SURVEYFREQ DATA=TEMP3; WEIGHT _WEIGHT; TABLES SMOK HEAVY_AMT NO_TRIAL NO_PLAN SMOK14 SMOK15 SMOK16 HEAVY_AMT14 HEAVY_AMT15 HEAVY_AMT16 NO_PLAN14 NO_PLAN15 NO_PLAN16 NO_TRIAL14 NO_TRIAL15 NO_TRIAL16; BY HARD14; ODS OUTPUT ONEWAY=F2_2; RUN; 

PROC SURVEYMEANS DATA=TEMP3; WEIGHT _WEIGHT; VAR AMOUNT AMOUNT14 AMOUNT15 AMOUNT16; BY HARD14; RUN;

* children in home;

DATA KWP9; SET DATASET.Koweps_hpda09_2014_beta3;
AGE14=2014-h09_g4; 
IF AGE14<19 THEN CHILD=1; ELSE CHILD=0;
RUN;

PROC SQL;
CREATE TABLE TEMP9 AS
SELECT *,
SUM(CHILD) AS CHILD14
FROM KWP9
GROUP BY H09_ID;
RUN;

DATA TEMP_KWP9; SET TEMP9; IF CHILD14=1 THEN CHILD_HOME14=1; ELSE CHILD_HOME14=0; HID=H09_ID;  KEEP HID CHILD14 CHILD_HOME14; RUN;
PROC SORT DATA=TEMP_KWP9 OUT=KWP9V2 NODUPKEY; BY HID; RUN;

DATA KWP10; SET DATASET.Koweps_hpc10_2015_beta2;
AGE15=2015-h10_g4; 
IF AGE15<19 THEN CHILD=1; ELSE CHILD=0;
RUN;

PROC SQL;
CREATE TABLE TEMP10 AS
SELECT *,
SUM(CHILD) AS CHILD15
FROM KWP10
GROUP BY H10_ID;
RUN;

DATA TEMP_KWP10; SET TEMP10; IF CHILD15=1 THEN CHILD_HOME15=1; ELSE CHILD_HOME15=0; HID=H10_ID;  KEEP HID CHILD15 CHILD_HOME15; RUN;
PROC SORT DATA=TEMP_KWP10 OUT=KWP10V2 NODUPKEY; BY HID; RUN;

PROC SORT DATA=KWP9V2; BY HID;PROC SORT DATA=KWP10V2; BY HID;
DATA A.KWP910_CHILD; MERGE KWP9V2 KWP10V2; BY HID; RUN;

DATA KWP11; SET DATASET.Koweps_hpwc11_2016_beta1;
AGE16=2016-h11_g4; 
IF AGE16<19 THEN CHILD=1; ELSE CHILD=0;
RUN;

PROC SQL;
CREATE TABLE TEMP11 AS
SELECT *,
SUM(CHILD) AS CHILD16
FROM KWP11
GROUP BY H11_ID;
RUN;

DATA TEMP_KWP11; SET TEMP11; IF CHILD16=1 THEN CHILD_HOME16=1; ELSE CHILD_HOME16=0; HID=H11_ID;  KEEP HID CHILD16 CHILD_HOME16; RUN;
PROC SORT DATA=TEMP_KWP11 OUT=KWP11V2 NODUPKEY; BY HID; RUN;

PROC SORT DATA=KWP9V2; BY HID; PROC SORT DATA=KWP10V2; BY HID; PROC SORT DATA=KWP11V2; BY HID;
DATA A.KWP91011_CHILD; MERGE KWP9V2 KWP10V2 KWP11V2; BY HID; RUN;




DATA NOPL; SET DATASET.Koweps_hp01_11_long_170331;

* YEAR: Á¶»ç±âÁس⵵, YEAR1: Á¶»ç³âµµ, WV: Á¶»çÂ÷¼ö;
YEAR1=YEAR+1;

IF YEAR1>=2008;

* ¼ºº°;
SEX=H_G3;

* ¿¬·É; 
AGE=YEAR1-H_G4;

* ÃÖ±Ù 1³â°£ ±Ý¿¬ ½Ãµµ (1:¿¹, 2: ¾Æ´Ï¿À);
IF p05_3aq7 IN (1) THEN NO_TRIAL=0;
IF p05_3aq7 IN (2) THEN NO_TRIAL=1;
IF p05_3aq7 IN (9) THEN NO_TRIAL=.;

* ±Ý¿¬ °èȹ (1: 1°³¿ù ¾È, 2: 6°³¿ù ¾È, 3: ¾ðÁ¨°¡´Â ÀÖ´Ù, 4: ÇöÀç·Î¼­´Â ¾ø´Ù);
NO_PLAN=p05_3aq8;
IF p05_3aq8 IN (4) THEN NO_PLAN=1;
ELSE IF p05_3aq8 IN (1,2,3) THEN NO_PLAN=0;
ELSE IF p05_3aq8 IN (9) THEN NO_PLAN=.;

KEEP YEAR1 H_PID SEX AGE NO_PLAN;

RUN;

* 2012³â NOPL;
PROC SQL;
CREATE TABLE NOPL2012 AS
SELECT *,
SUM(NO_PLAN) AS SUM_NO_PLAN
FROM NOPL
WHERE YEAR1 IN (2008:2012)
GROUP BY H_PID;
RUN;

DATA NOPL12; SET NOPL2012; IF YEAR1 IN (2012); IF SUM_NO_PLAN=5 THEN NOPL=1; ELSE NOPL=0; KEEP H_PID NOPL YEAR1; RUN;

* 2013³â NOPL;
PROC SQL;
CREATE TABLE NOPL2013 AS
SELECT *,
SUM(NO_PLAN) AS SUM_NO_PLAN
FROM NOPL
WHERE YEAR1 IN (2009:2013)
GROUP BY H_PID;
RUN;

DATA NOPL13; SET NOPL2013; IF YEAR1 IN (2013);IF SUM_NO_PLAN=5 THEN NOPL=1; ELSE NOPL=0; KEEP H_PID NOPL YEAR1; RUN;

* 2014³â NOPL;
PROC SQL;
CREATE TABLE NOPL2014 AS
SELECT *,
SUM(NO_PLAN) AS SUM_NO_PLAN
FROM NOPL
WHERE YEAR1 IN (2010:2014)
GROUP BY H_PID;
RUN;

DATA NOPL14; SET NOPL2014; IF YEAR1 IN (2014); IF SUM_NO_PLAN=5 THEN NOPL=1; ELSE NOPL=0; KEEP H_PID NOPL YEAR1; RUN;

* 2015³â NOPL;
PROC SQL;
CREATE TABLE NOPL2015 AS
SELECT *,
SUM(NO_PLAN) AS SUM_NO_PLAN
FROM NOPL
WHERE YEAR1 IN (2011:2015)
GROUP BY H_PID;
RUN;

DATA NOPL15; SET NOPL2015; IF YEAR1 IN (2015);IF SUM_NO_PLAN=5 THEN NOPL=1; ELSE NOPL=0; KEEP H_PID NOPL YEAR1; RUN;

* 2016³â NOPL;
PROC SQL;
CREATE TABLE NOPL2016 AS
SELECT *,
SUM(NO_PLAN) AS SUM_NO_PLAN
FROM NOPL
WHERE YEAR1 IN (2012:2016)
GROUP BY H_PID;
RUN;

DATA NOPL16; SET NOPL2016; IF YEAR1 IN (2016); IF SUM_NO_PLAN=5 THEN NOPL=1; ELSE NOPL=0; KEEP H_PID NOPL YEAR1; RUN;

DATA A.NOPL_TOTAL; SET NOPL12-NOPL16; RUN;

This snippet took 0.14 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).