- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
My collaborator sent me his Stata codes. I only use SAS so need help to convert STATA codes to SAS codes for a longitudinal data variable:
Following are his codes:
forvalues i=1/13{
gen r`i'ins=1 if r`i'higov==1
replace r`i'ins=2 if r`i'higov==1 & r`i'covr==1
replace r`i'ins=2 if r`i'higov==1 & r`i'covs==1
replace r`i'ins=3 if r`i'higov==1 & r`i'hiothp==1
replace r`i'ins=4 if (r`i'covr==1 | r`i'covs==1) & r`i'ins==.
replace r`i'ins=5 if r`i'hiothp==1 & r`i'ins==.
replace r`i'ins=6 if r`i'higov==0 & r`i'covr==0 & r`i'covs==0 & r`i'hiothp==0
capture label define r`i'ins 1"Government Insurance Only" 2"Governemnt and Employer" ///
3"Government and Other" 4"Employer Only" 5"Other Only" 6"No Insurance"
label value r`i'ins r`i'ins
}
Appreciate your help.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
ARRAY processing should solve your problem. What is the naming pattern for your variables? Is it something like this?
array rhigovs (13) r1higov r2higov r3higov r4higov r5higov r6higov
r7higov r8higov r9higov r10higov r11higov r12higov r13higov;
array rins (13) r1ins......................r13ins;
do i = 1 to dim(rhigovs);
<put your array logic here.>
if rhigovs(i) = 1 then rins(i) = 1;
<etc>
end;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Ask your collaborator what this does and we'll try to help.
It looks like just a few tests.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The Stata codes were to generate a new insurance categorical variable (r{*}ins, i is from 1 to 13) within each study id repeating for 13 years which is a long form of data.
Here is what I have figured out:
The last part of the Stata codes were to format the riins, which can be converted to following SAS codes:
PROC FORMAT;
VALUE ins_fmt
1 = "Government Insurance Only"
2 = "Government Insurance and Employer"
3 = "Government Insurance and Other"
4 = "Employer Only"
5 = "Other only"
6 = "No Insurance";
RUN;
I still need help to write the SAS codes for all 13 years within each study id.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
ARRAY processing should solve your problem. What is the naming pattern for your variables? Is it something like this?
array rhigovs (13) r1higov r2higov r3higov r4higov r5higov r6higov
r7higov r8higov r9higov r10higov r11higov r12higov r13higov;
array rins (13) r1ins......................r13ins;
do i = 1 to dim(rhigovs);
<put your array logic here.>
if rhigovs(i) = 1 then rins(i) = 1;
<etc>
end;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for your help.