Quantcast
Channel: Statalist
Viewing all articles
Browse latest Browse all 65561

Purging observations by subgroup

$
0
0
I'm sure there is a solution already on the forum about this but I wasn't able to find anything with my searches...

I have a dataset of lab values for which I have generated a % change since baseline variable [change]. Now I want to purge all records, by lab test, for which the % change at all post-baseline timepoints is less than 5%.

In the example dataset below I want to purge all of the ALP results for Subject A since the % change at all post day1 timepoints is less than 5%. All records for subject B should be retained since all AST results change by >5% and only the day2 ALP result is <5%...

My real dataset contains many subjects, many timepoints (which are not present for all subjects) and many lab tests (which again are not all present for all subjects/timepoints).

Code:
* Example generated by -dataex-. To install: ssc install    dataex
clear
input str1 subject str4 timepoint str3 test float(result    change)
"A" "day1" "alp" 100   .
"A" "day1" "ast" 100   .
"A" "day2" "alp" 100   0
"A" "day2" "ast"  50 -50
"A" "day3" "alp" 101   1
"A" "day3" "ast"  50 -50
"B" "day1" "alp" 100   .
"B" "day1" "ast" 100   .
"B" "day2" "alp" 101   1
"B" "day2" "ast" 150  50
"B" "day3" "alp" 150  50
"B" "day3" "ast" 150  50
end

Viewing all articles
Browse latest Browse all 65561

Trending Articles