Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: egen anycount problem

From   paul gross <>
To   <>
Subject   st: egen anycount problem
Date   Fri, 17 May 2013 10:00:16 +1000

Dear statalisters

Working with stata 12 and a large dataset of 2.2 million hospital admissions where  patients can have multiple or single admissions, I want to count how many GP visits (code 8) occurred in the 30 days prior to admission.I have up to 25 prior service indicators (prior_service_turps_1 – prior_service_turps_25) that can contain the type 8 ( or 15 other)  types of doctor encounter. I first destringed these 25 PSIs.

My stata coding below  is intended to return for each admission the total number of code 8 in the 25 positions. I also am checking the total of missing values in the 25 positions as more missing codes is one of my indicators of poor access to medical services

sort clt_unique_id admission_date 

destring prior_service_turps_1 - prior_service_turps_25,gen(destrprior_service_turps_1 - destrprior_service_turps_25) 

foreach v of varlist destrprior_service_turps_1 - destrprior_service_turps_25 {

egen missDS=rowmiss(destrprior_service_turps_1 - destrprior_service_turps_25)

egen  c08=anycount(`v') if `v' !=., values (8)


tab c08

list obsno patno missDS c08 destrprior_service_turps_1 - destrprior_service_turps_3 

This coding produces the following values for patient no 18 , who clearly should have 3 code 8 recorded in variable c08, but has only 1 

     | obsno | patno | c08 | destr~_1 | prio~s_2 | destr~_2 | prio~s_3 | destr~_3 |

     |    68      |    18   |   1   |        8         |      008     |        8        |      008     |        8 

Two probs.
  1. The c08 total is wrong.
  2. The list variables do not include the original stringed prior service codes, only the destringed versions, yet prio~s_2 and prio~s_3 are listed
Have I misused the egen anycount specification?    

Paul Gross

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index