Hi!
I have a very large dataset of about 1500 patients. Each row in my dataset is a hospital-admission of one of these patients, and I have about 93,000 hospital admissions.
Each patient have an ID-number, in my dataset titled "newid".
I struggle with getting to analyse on my data, as I can't figure out how to get Stata to count each unique ID-number as a person.
I have tried multiple things, for example reshaping from long to wide, but as I have a lot of variables in my dataset, this doesn't really work.
What I really want is an option of making a command that basically tells Stata: "Give me the number of myocardial infarctions (variable "myocard"), IF there is a unique ID-number" or "Give me the distribution of female/male (variable "sex") IF counting each unique ID-number as a person"
I have coded it so that variables like age, myocardial infarction yes/no etc. is constant for all rows containing data on a specific patient.
I have tried to use dataex, I hope I'm doing it right.
In case the above doesn't work, the data is structured as such:
I am using Stata 14.2.
Let me know if you have any ideas on how to do this - I have trawled the internet for a solution, but haven't found anything else than reshaping, which I would like to not do.
All the best,
I have a very large dataset of about 1500 patients. Each row in my dataset is a hospital-admission of one of these patients, and I have about 93,000 hospital admissions.
Each patient have an ID-number, in my dataset titled "newid".
I struggle with getting to analyse on my data, as I can't figure out how to get Stata to count each unique ID-number as a person.
I have tried multiple things, for example reshaping from long to wide, but as I have a lot of variables in my dataset, this doesn't really work.
What I really want is an option of making a command that basically tells Stata: "Give me the number of myocardial infarctions (variable "myocard"), IF there is a unique ID-number" or "Give me the distribution of female/male (variable "sex") IF counting each unique ID-number as a person"
I have coded it so that variables like age, myocardial infarction yes/no etc. is constant for all rows containing data on a specific patient.
I have tried to use dataex, I hope I'm doing it right.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float newid byte sex float(myocard cerebro tumor CCI) 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 2 1 0 0 0 0 2 1 0 0 0 0 2 1 0 0 0 0 2 1 0 0 0 0 2 1 0 0 0 0 2 1 0 0 0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label values cerebro yesnolabel label values tumor yesnolabel label def yesnolabel 0 "no", modify label def yesnolabel 1 "yes", modify
Admission | newid | sex | age | myocardial infarction | Dementia |
1 | 1 | 1 | 70 | 1 | 0 |
2 | 1 | 1 | 70 | 1 | 0 |
3 | 1 | 1 | 70 | 1 | 0 |
1 | 2 | 0 | 61 | 0 | 0 |
2 | 2 | 0 | 61 | 0 | 0 |
3 | 2 | 0 | 61 | 0 | 0 |
4 | 2 | 0 | 61 | 0 | 0 |
1 | 3 | 1 | 83 | 1 | 1 |
2 | 3 | 1 | 83 | 1 | 1 |
I am using Stata 14.2.
Let me know if you have any ideas on how to do this - I have trawled the internet for a solution, but haven't found anything else than reshaping, which I would like to not do.
All the best,
Comment