Midterm part 2 I

Midterm part 2 I

by Richard Hu -
Number of replies: 3

I am trying to create the variable that indicates whether a patient ever identified as HIV+. I want to use the following code:

egen sero = max(hiv_cat), by(id)         

where hiv_cat is hivstatus recoded as a categorical variable. However, I receive the error messages that egen is an unrecognized function and the by option is not allowed. I'm using Stata v. 16 through the RAE. Thank you for your help,

RH

In reply to Richard Hu

Re: Midterm part 2 I

by Crystal Langlais -
Hi Richard,

Thanks for posting. Despite the error message you noted, I think the error with your command is the max() function you are using. max() expects a function, not a variable. You can read more about the functions and their expected inputs using "help egen".

As alluded to in the announcements, we want you to use the user-generated xfill command for this question. It will take a few lines of code. Please let us know if you have any questions as you proceed.
In reply to Crystal Langlais

Re: Midterm part 2 I

by Richard Hu -
I was able to run the code using the do file (and afterwards using the command menu), but prior to that, it wouldn't work in the command menu. I never figured out why this was the case, but the code was exactly the same. Here is the webpage I used as a reference, if you're interested https://www.stata.com/support/faqs/data-management/create-variable-recording/ .

Thank you
In reply to Richard Hu

Re: Midterm part 2 I

by Crystal Langlais -
Thanks for sharing. For those of you following along, it looks like by passing hiv_cat into max(), Stata evaluates if hiv_cat is true (1) or false (0). I would have expected you had to use a full expression (hiv_cat == 1) but looks like Stata recognizes the shorthand for binary variables.