Demo entry 6678027

Youth

   

Submitted by anonymous on Dec 05, 2017 at 04:04
Language: SAS. Code size: 8.1 kB.

LIBNAME A 'D:\Dropbox\data\dataset';
LIBNAME DATASET 'D:\Dropbox\data\dataset';


****************2010년 센서스 인구(15-19세)*************
15세 0.247172732
16세 0.249718333
17세 0.249087093
18세 0.254021842


0.247172732 0.249718333 0.249087093 0.254021842

*******************************************;





*******각 조사에 연도 넣기**************;


DATA KYRBS2014; SET  DATASET.KYRBS2014;
PERSON=SUBSTR(OBS, 2, 6);
PERSON1=PERSON+0;
ID=PERSON1*10000+2014;
YEAR=2014;
RUN;

DATA KYRBS2015; SET  DATASET.KYRBS2015;
PERSON=SUBSTR(OBS, 2, 6);
PERSON1=PERSON+0;
ID=PERSON1*10000+2015;
YEAR=2015;
RUN;


****************결측 포함 데이터 만들기**************;


DATA TEST; SET KYRBS2014 KYRBS2015;


***15~18세 한정***;

IF 15=<AGE<=18;

IF AGE=15 THEN AGEC=1;
IF AGE=16 THEN AGEC=2;
IF AGE=17 THEN AGEC=3;
IF AGE=18 THEN AGEC=4;


*****중학생 제외*****;
IF SCHOOL IN ("중학교") THEN DELETE;


******경북, 경남, 울산, 부산 남기고 나머지 제외*****;

IF CITY IN ("서울") THEN DELETE;
IF CITY IN ("경기") THEN DELETE;
IF CITY IN ("인천") THEN DELETE;
IF CITY IN ("광주") THEN DELETE;
IF CITY IN ("세종") THEN DELETE;
IF CITY IN ("강원") THEN DELETE;
IF CITY IN ("충북") THEN DELETE;
IF CITY IN ("충남") THEN DELETE;
IF CITY IN ("전남") THEN DELETE;
IF CITY IN ("전북") THEN DELETE;
IF CITY IN ("제주") THEN DELETE;
IF CITY IN ("대전") THEN DELETE;
IF CITY IN ("대구") THEN DELETE;

IF CITY IN ("경북") THEN CITY1=1;
IF CITY IN ("경남") THEN CITY1=2;
IF CITY IN ("울산") THEN CITY1=3;
IF CITY IN ("부산") THEN CITY1=4;


********정책 시행 BINARY로 만들기*******;
IF CITY1=1 THEN POLICY=0;
IF CITY1=2 THEN POLICY=1;
IF CITY1=3 THEN POLICY=0;
IF CITY1=4 THEN POLICY=1;


***********성별 BINARY로 만들기**********;
IF SEX=1 THEN FEMALE=0;
IF SEX=2 THEN FEMALE=1;



*********연도변수 BINARY로 만들기*******;

DO; IF YEAR=2015 THEN POST=1; ELSE POST=0; END;



***********24시 이전 취침했을 때 수면시간******************;
IF 12=<M_SLP_HR<=23 THEN DO;
WDSLEEP1=(24-M_SLP_HR)*60 + (60-M_SLP_MM) + M_WK_HR*60 + M_WK_MM;
WDSLEEP=WDSLEEP1/60;
END;



***********새벽 1시 이후 취침했을 때 수면시간**************************;
ELSE IF M_SLP_HR<=12 THEN DO;
WDSLEEP1=(M_WK_HR*60 + M_WK_MM) - (M_SLP_HR*60 + M_SLP_MM);
WDSLEEP=WDSLEEP1/60;
END;


************잠든 시각이 24시일 경우******;
ELSE IF M_SLP_HR=24 THEN DO;
WDSLEEP1=(M_WK_HR*60 + M_WK_MM) - (M_SLP_HR*0 + M_SLP_MM);
WDSLEEP=WDSLEEP1/60;
END;



***********잠으로 피로회복정도***************************;
IF M_SLP_EN IN (1:2) THEN RECOVER=1;
ELSE IF M_SLP_EN IN (3:5) THEN RECOVER=0;


RUN;


**********N수, 결측 확인*********;
PROC SORT DATA=TEST; BY  SEX ; RUN;
PROC FREQ DATA=TEST; TABLES AGE POLICY YEAR  CITY1 SEX RECOVER WDSLEEP /MISSING; RUN;




*********결측 제외********;

DATA KYRBS1415; SET KYRBS2014 KYRBS2015;


***15~18세 한정***;

IF 15=<AGE<=18;

IF AGE=15 THEN AGEC=1;
IF AGE=16 THEN AGEC=2;
IF AGE=17 THEN AGEC=3;
IF AGE=18 THEN AGEC=4;


*****중학생 제외*****;
IF SCHOOL IN ("중학교") THEN DELETE;


******경북, 경남, 울산, 부산 남기고 나머지 제외*****;

IF CITY IN ("서울") THEN DELETE;
IF CITY IN ("경기") THEN DELETE;
IF CITY IN ("인천") THEN DELETE;
IF CITY IN ("광주") THEN DELETE;
IF CITY IN ("세종") THEN DELETE;
IF CITY IN ("강원") THEN DELETE;
IF CITY IN ("충북") THEN DELETE;
IF CITY IN ("충남") THEN DELETE;
IF CITY IN ("전남") THEN DELETE;
IF CITY IN ("전북") THEN DELETE;
IF CITY IN ("제주") THEN DELETE;
IF CITY IN ("대전") THEN DELETE;
IF CITY IN ("대구") THEN DELETE;

IF CITY IN ("경북") THEN CITY1=1;
IF CITY IN ("경남") THEN CITY1=2;
IF CITY IN ("울산") THEN CITY1=3;
IF CITY IN ("부산") THEN CITY1=4;


********정책 시행 BINARY로 만들기*******;
IF CITY1=1 THEN POLICY=0;
IF CITY1=2 THEN POLICY=1;
IF CITY1=3 THEN POLICY=0;
IF CITY1=4 THEN POLICY=1;


***********성별 BINARY로 만들기**********;
IF SEX=1 THEN FEMALE=0;
IF SEX=2 THEN FEMALE=1;



*********연도변수 BINARY로 만들기*******;

DO; IF YEAR=2015 THEN POST=1; ELSE POST=0; END;



***********24시 이전 취침했을 때 수면시간******************;
IF 12=<M_SLP_HR<=23 THEN DO;
WDSLEEP1=(24-M_SLP_HR)*60 + (60-M_SLP_MM) + M_WK_HR*60 + M_WK_MM;
WDSLEEP=WDSLEEP1/60;
END;



***********새벽 1시 이후 취침했을 때 수면시간**************************;
ELSE IF M_SLP_HR<=12 THEN DO;
WDSLEEP1=(M_WK_HR*60 + M_WK_MM) - (M_SLP_HR*60 + M_SLP_MM);
WDSLEEP=WDSLEEP1/60;
END;


************잠든 시각이 24시일 경우******;
ELSE IF M_SLP_HR=24 THEN DO;
WDSLEEP1=(M_WK_HR*60 + M_WK_MM) - (M_SLP_HR*0 + M_SLP_MM);
WDSLEEP=WDSLEEP1/60;
END;



***********잠으로 피로회복정도***************************;
IF M_SLP_EN IN (1:2) THEN RECOVER=1;
ELSE IF M_SLP_EN IN (3:5) THEN RECOVER=0;



******결측치 제거*****;
IF WDSLEEP=. THEN DELETE;
IF RECOVER=. THEN DELETE;
IF POLICY=. THEN DELETE;
IF FEMALE=. THEN DELETE;
IF AGE=. THEN DELETE;


RUN;




**********N수 확인*********;
PROC SORT DATA=KYRBS1415; BY CITY1 YEAR; RUN;
PROC FREQ DATA=KYRBS1415; TABLES AGE*SEX SEX*RECOVER SEX*WDSLEEP /MISSING; BY CITY1 YEAR; RUN;
PROC FREQ DATA=KYRBS1415; TABLES SEX AGE SEX*AGE WDSLEEP /MISSING; RUN;




* 새로운 가중치 산출 (NEW_WT);
PROC MEANS DATA=KYRBS1415 N SUM NOPRINT; 
CLASS YEAR SEX;
VAR W ; 
OUTPUT OUT=WT1 N(W)=N_WT SUM(W)=SUM_WT;
RUN;

DATA WT2; SET WT1; 
IF _TYPE_=3; 
DROP _TYPE_ _FREQ_;
RUN;

PROC SORT DATA=KYRBS1415; BY YEAR SEX; RUN;
PROC SORT DATA=WT2; BY YEAR SEX; RUN;

DATA A.KYRBS1415; MERGE KYRBS1415  WT2;  BY YEAR SEX;
NEW_WT=W*N_WT /SUM_WT; 
RUN;




************************************경북, 경남//// 경북 CITY1=1, 경남 CITY1=2***********************;


***************연도별 WDSLEEP 계산**************;
PROC GENMOD DATA=A.KYRBS1415 DESCENDING; WHERE CITY1 IN (1:2);
WEIGHT NEW_WT; 
CLASS  AGEC POST(REF='0') POLICY(REF='0') FEMALE(REF='0') STRATA CLUSTER;
MODEL WDSLEEP = AGEC FEMALE POST|POLICY /DIST=NORMAL LINK=IDENTITY ;
REPEATED SUBJECT=CLUSTER(STRATA);
ESTIMATE 'DIFFERENCE IN DIFFERENCE' POLICY*POST 1 -1 -1 1 ;
LSMEANS POST|POLICY /DIFF;
OUTPUT OUT=PRED P=PHAT;
RUN;

PROC TABULATE DATA=PRED MISSING;
CLASS POLICY POST;
VAR PHAT;
TABLE POST, POLICY*PHAT*MEAN;
RUN;

*****95% CI******;
PROC MEANS DATA=PRED MAXDEC=4 MISSING MEAN CL;
VAR PHAT;
CLASS POST POLICY;
RUN;



*******연도별 RECOVER계산*********;

PROC GENMOD DATA=A.KYRBS1415 DESCENDING; WHERE CITY1 IN (1:2);
WEIGHT NEW_WT; 
CLASS  AGEC POST(REF='0') POLICY(REF='0') FEMALE(REF='0') STRATA CLUSTER;
MODEL RECOVER = AGEC FEMALE POST|POLICY /DIST=BINOMIAL LINK=LOGIT ;
REPEATED SUBJECT=CLUSTER(STRATA);
ESTIMATE 'DIFFERENCE IN DIFFERENCE' POLICY*POST 1 -1 -1 1 ;
LSMEANS POST|POLICY /DIFF;
OUTPUT OUT=PRED P=PHAT;
RUN;

PROC TABULATE DATA=PRED MISSING;
CLASS POLICY POST;
VAR PHAT;
TABLE POST, POLICY*PHAT*MEAN;
RUN;

*****95% CI******;
PROC MEANS DATA=PRED MAXDEC=4 MISSING MEAN CL;
VAR PHAT;
CLASS POST POLICY;
RUN;



***************************울산,부산/////울산 CITY1=3, 부산 CITY1=4************************;



***************연도별 WDSLEEP 계산**************;

PROC GENMOD DATA=A.KYRBS1415 DESCENDING; WHERE CITY1 IN (3:4);
WEIGHT NEW_WT; 
CLASS  AGEC POST(REF='0') POLICY(REF='0') FEMALE(REF='0') STRATA CLUSTER;
MODEL WDSLEEP = AGEC FEMALE POST|POLICY /DIST=NORMAL LINK=IDENTITY ;
REPEATED SUBJECT=CLUSTER(STRATA);
ESTIMATE 'DIFFERENCE IN DIFFERENCE' POLICY*POST 1 -1 -1 1 ;
LSMEANS POST|POLICY /DIFF;
OUTPUT OUT=PRED P=PHAT;
RUN;

PROC TABULATE DATA=PRED MISSING;
CLASS POLICY POST;
VAR PHAT;
TABLE POST, POLICY*PHAT*MEAN;
RUN;

*****95% CI******;
PROC MEANS DATA=PRED MAXDEC=4 MISSING MEAN CL;
VAR PHAT;
CLASS POST POLICY;
RUN;



*******연도별 RECOVER계산*********;

PROC GENMOD DATA=A.KYRBS1415 DESCENDING; WHERE CITY1 IN (3:4);
WEIGHT NEW_WT; 
CLASS  AGEC POST(REF='0') POLICY(REF='0') FEMALE(REF='0') STRATA CLUSTER;
MODEL RECOVER = AGEC FEMALE POST|POLICY /DIST=BINOMIAL LINK=LOGIT ;
REPEATED SUBJECT=CLUSTER(STRATA);
ESTIMATE 'DIFFERENCE IN DIFFERENCE' POLICY*POST 1 -1 -1 1 ;
LSMEANS POST|POLICY /DIFF;
OUTPUT OUT=PRED P=PHAT;
RUN;

PROC TABULATE DATA=PRED MISSING;
CLASS POLICY POST;
VAR PHAT;
TABLE POST, POLICY*PHAT*MEAN;
RUN;

*****95% CI******;
PROC MEANS DATA=PRED MAXDEC=4 MISSING MEAN CL;
VAR PHAT;
CLASS POST POLICY;
RUN;

This snippet took 0.03 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).