Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: Linking a patient file with an event file


From   Carl Severson <[email protected]>
To   [email protected]
Subject   Re: st: Linking a patient file with an event file
Date   Sun, 3 Mar 2013 14:03:31 -0700

I had a typo in my code. Try this:

      by id2013: gen edcount = _N
      by id2013: gen visit = _n
      reshape wide visitVariable visitDate etc, i(id2013) j(visit)

... it is possible that I am misunderstanding how you want your data
formated. If the above code doesn't work, maybe let me know a bit more
specifics about the data you have, the format it is in, and the format
you want it in. An example of your data (or fake data in the same
structure as your actual data) might be useful.

Cheers
Carl

On Sun, Mar 3, 2013 at 1:36 PM, Lisa Cook <[email protected]> wrote:
> Hi Carl,
>
> I'm not at the University of Calgary, but thanks for the offer! I
> really appreciate the help.
>
> Using the code you suggest, I get a variable that takes the values
> edcount = 1 for the first visit, edcount = 2 for the second, edcount =
> 3 for the third, and so on. Thus, when I reshape, I get an error if I
> try to leave the edcount variable off my list of variables, because
> it's not a constant value. Is there a way to just keep the highest
> value of edcount for each person?
>
> Lisa
>
> On Sun, Mar 3, 2013 at 3:01 PM, Carl Severson <[email protected]> wrote:
>> Hey Lisa, glad it helped.
>>
>> I think there is an easier solution than a foreach loop. Will this
>> accomplish what you want?
>>
>>      by id2013: gen edcount = _n
>>      by id2013: gen visit = _n
>>      reshape wide visitVariable, i(id2013) j(visit)
>>
>> This should give you a single line per person, with a variable that
>> has the number of visits per person.
>>
>> Out of curiosity, what kind of models are you running?
>>
>> Hope that helps.
>>
>> p.s. In the rare, rare chance that you are located at the University
>> of Calgary, I'd be happy to sit down with you in person and help with
>> you data management issues.
>>
>> Carl
>>
>> On Sun, Mar 3, 2013 at 12:30 PM, Lisa Cook <[email protected]> wrote:
>>> Thank you, Carl.
>>>
>>> The code you suggested worked, but once the reshaping is done, I no
>>> longer have an edcount variable (it turns into edcount1, edcount2,
>>> edcount3, etc.). I thought maybe I could use a macro to replace all
>>> the values of edcount with 1 if nonmissing and 0 if missing, then sum
>>> them to get a new count variable. I thought I would try doing it one
>>> step at a time, since I'm inexperienced with macros.
>>>
>>> foreach var of varlist `edcount?' {
>>>   replace `var' = 1 if `var' !=.
>>> }
>>>
>>> This results in the error "varlist required". Any ideas?
>>>
>>> Thanks!
>>> Lisa
>>> *
>>> *   For searches and help try:
>>> *   http://www.stata.com/help.cgi?search
>>> *   http://www.stata.com/support/faqs/resources/statalist-faq/
>>> *   http://www.ats.ucla.edu/stat/stata/
>> *
>> *   For searches and help try:
>> *   http://www.stata.com/help.cgi?search
>> *   http://www.stata.com/support/faqs/resources/statalist-faq/
>> *   http://www.ats.ucla.edu/stat/stata/
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index