Hi Statalist,
Thanks for being a great forum which already has helped a lot!
I'm new here, quite fresh to STATA and trying to organize a data file this summer for cancer epidemiology research.
In my data file, I have a string variable "Diagnoses" for ICD-codes for various diseases, where the ICD-codes for cancer starts with the letter "C".
I would like to make STATA select all the cancer diagnoses into a separate variable, and have based on a previous thread tried the command
gen Cancer =.
replace Cancer = 1 if word(Diagnoses,1),"C"
but get the error message "type mismatch" here.
When changing to
gen Cancer=""
replace Cancer = 1 if word(Diagnoses,1),"C"
the same error message pops up so not sure if the mismatch is from Diagnoses being a string variable. Maybe I'm doing something else wrong?
Would be thankful for any advice on how to go around this.
Best,
Mary
Related Posts with Making new variable from first letter of string variable
panel regressionHi everyone, apologies if I am bothering with very simple questions, I am a beginner on panel data a…
Adding custom stats in a tableHello, I'm trying to create a custom table with some specific stats, namely, I want to see how many…
Help designing an algorithm that takes in logistic regression model and generates a forest plotI'm new to STATA and can think of ways of doing this in R but I'm just having trouble figuring out w…
Statistical Test Selection AdviceHi, If possible, I'd like to obtain advice regarding the correct / best statistical test to use for …
Simple sum programI am trying to write out a simple sum program in STATA. I need this program t use in one of my othe …
Subscribe to:
Post Comments (Atom)
0 Response to Making new variable from first letter of string variable
Post a Comment