I need to convert this code from SAS to Stata. I'm a newbie Stata user (2 months) (previously SPSS). I used SAS 30 years ago! I think its pretty straight forward!
Can anyone help? Data file has up to two records per person, security issues wont let me convert long format to wide format. So:
DATA TEMP;
SET PSS12EMA;
PROC SORT;
BY ABSHHID;
DATA TEMP1 (KEEP = ABSHHID EATYPNA EATYPNB EATYPNC EATYPND EATCNT WTHECO);
SET TEMP;
BY ABSHHID;
IF FIRST.ABSHHID THEN DO; EATYPNA=0; EATYPNB=0; EATYPNC=0; EATYPND=0; EATCNT=0; WTHECO=0; END;
RETAIN EATYPNA EATYPNB EATYPNC EATYPND;
IF EATYPCE=5 THEN EATYPNA=1;
IF EATYPCF=6 THEN EATYPNB=1;
IF EATYPCG=7 THEN EATYPNC=1;
IF EATYPCH=8 THEN EATYPND=1;
IF LAST.ABSHHID THEN DO;
EATCNT=EATYPNA+EATYPNB+EATYPNC+EATYPND;
IF 1<=EATCNT THEN WTHECO=1; ELSE WTHECO=5;
OUTPUT;
END;
Can anyone help? Data file has up to two records per person, security issues wont let me convert long format to wide format. So:
DATA TEMP;
SET PSS12EMA;
PROC SORT;
BY ABSHHID;
DATA TEMP1 (KEEP = ABSHHID EATYPNA EATYPNB EATYPNC EATYPND EATCNT WTHECO);
SET TEMP;
BY ABSHHID;
IF FIRST.ABSHHID THEN DO; EATYPNA=0; EATYPNB=0; EATYPNC=0; EATYPND=0; EATCNT=0; WTHECO=0; END;
RETAIN EATYPNA EATYPNB EATYPNC EATYPND;
IF EATYPCE=5 THEN EATYPNA=1;
IF EATYPCF=6 THEN EATYPNB=1;
IF EATYPCG=7 THEN EATYPNC=1;
IF EATYPCH=8 THEN EATYPND=1;
IF LAST.ABSHHID THEN DO;
EATCNT=EATYPNA+EATYPNB+EATYPNC+EATYPND;
IF 1<=EATCNT THEN WTHECO=1; ELSE WTHECO=5;
OUTPUT;
END;