BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Artp
Fluorite | Level 6

Hello Friends,

 

I am not STATA user. I tried to understand this language so I could translate its code into SAS. I need your input in certifying that my SAS code is equivalent to the Stata code.

 

/*Example STATA code:*/
 
gen strataid=.
replace strataid=(GESTFIPS*10000)+ HG_MSAC if HG_MSAC > 0
replace strataid =(GESTFIPS*1000) + GECO if GECO > 0 & HG_MSAC==0
replace strataid = GESTFIPS if GECO == 0 & HG_MSAC == 0

 

This is how I converted the above code into SAS:
................................;
length STRATAID 4;
set stratumxplr; 
 
 if missing(GECO) then call missing (STRATAID);
 if missing (HG_MSAC) then call missing (STRATAID);
 if missing (GESTFIPS) then call missing (STRATAID);
 if GTCBSA > 0 then STRATAID = (GESTFIPS*10000) + GTCBSA;
    else if GTCO > 0 and GTCBSA = 0 then STRATAID = (GESTFIPS*1000) + GTCO;
     else if GTCO = 0 and GTCBSA = 0 then STRATAID = GESTFIPS;
 label STRATAID = 'Stratum Identification';
run;

Are the Stata double == equal signs equivalent to SAS one equal sign?

Stata code is from Michael Davern et al. p. 14 (http://journals.sagepub.com/doi/pdf/10.5034/inquiryjrnl_43.3.283).

 

Thanks for your help,

 

Artp

====

 

1 ACCEPTED SOLUTION
3 REPLIES 3
Tom
Super User Tom
Super User

It looks like the STATA code is unconditionally initiating the new variable to missing.

 

It does not look like the STATA code is using anything that is the equivalent of the ELSE statements in your code.  But since the conditions look to be mutually exclusive it shouldn't matter.

 

Why did use set the LENGTH of your new variable to 4?  SAS uses 64bit floating point numbers for all numeric variables. Storing only 4 of the 8 bytes will potentially remove some of the precision of the values.

 

In SAS equality testing is done with a single equal sign. Or the EQ keyword.

 

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 2016 views
  • 0 likes
  • 3 in conversation