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!
I'm using a government dataset and I want to create one record per person, and the new variables are whether or
Data file has up to two records per person (17,259 records, 17,050 unique IDs (ABSHHID) 30 variables). Security issues wont let me convert long format to wide format. I actually am not even sure if the SAS code they sent me does what I want it to do.
This is what I want to do on a made up dataset. Its fairly simple question I think, has each person ever owned a v1Dog v2Cat v3Rabbit?
ABSHHID NowOrBefore OwnDog OwnCat OwnRabbit
1 Now 1 1 0
1 Before 1 0 1
2 Now 0 0 0
2 Before 1 1 0
3 Now 0 0 0
4 Now 0 0 0
This is their code:
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;
Tags: convert SAS, loop, syntax
I'm using a government dataset and I want to create one record per person, and the new variables are whether or
Data file has up to two records per person (17,259 records, 17,050 unique IDs (ABSHHID) 30 variables). Security issues wont let me convert long format to wide format. I actually am not even sure if the SAS code they sent me does what I want it to do.
This is what I want to do on a made up dataset. Its fairly simple question I think, has each person ever owned a v1Dog v2Cat v3Rabbit?
ABSHHID NowOrBefore OwnDog OwnCat OwnRabbit
1 Now 1 1 0
1 Before 1 0 1
2 Now 0 0 0
2 Before 1 1 0
3 Now 0 0 0
4 Now 0 0 0
This is their code:
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;
Tags: convert SAS, loop, syntax
Comment