Converting String Variables (final)

Converting String Variables (final)

by Paul Takamoto -
Number of replies: 2

I'm hoping to get some help with how to best "clean" my initial data that contains string variables with particular issue below...

I am reviewing the use of naloxone to reverse opioid overdose in patients who present to the emergency department. Since there are various routes that this antidote can be administered, data was collected on route of administration. Unfortunately, the route of administration was recorded as a string variable. When I find individual patients who received only one route, there is no issue. I am having issues when patients receive the antidote via multiple routes. If a patient received intranasal AND intravenous naloxone it will list them as "intranasal, intravenous" in string format which assigns a different numeric value than if it were either one alone.

I would like to assign something like 1=intranasal, 2=intravenous, 3=nebulization in order to further analyze the data for tabulation. Currently any new combination of routes assigns a new value using the "encode" command. Does anyone have suggestions on how to clean up this issue? I'm hoping that this does not require manual manipulation.


Also I am having issues with formatting date and time of medication administration:

For example, current formatĀ  reads "6/23/2014 14:00" but I can't seem to use the gen date command. Is this because I need to separate time from date? Is there another command line that incorporates both?

Thanks for any help you all can provide!

Paul

In reply to Paul Takamoto

Re: Converting String Variables (final)

by Carol Paxson -

Hey, what about trying the Stata command "split" for your strings? Type "man split" in the command window to get a manual page on how to use split. As for the date, try "clock". As usual with Stata, I think the returned value is the date since 1/1/1960 or whatever, in Stata's internal format. --Carol

In reply to Paul Takamoto

Re: Converting String Variables (final)

by Amanda Irish -
Hi Paul, echoing Carol's excellent suggestions. Here are a few resources with some worked examples in case they're helpful:

https://www.stata.com/support/faqs/data-management/splitting-string-variable/
https://blog.stata.com/2015/12/17/a-tour-of-datetime-in-stata-i/