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: Database problem


From   roland andersson <[email protected]>
To   [email protected]
Subject   Re: st: Database problem
Date   Sat, 8 Dec 2012 17:07:12 +0100

Thank you Nix for you very kind effort.
I am a beginner in Stata programming. I will look more in detail in
your program, just for learning.

I did my own program for fusing the observation with same date, and I
finally got this working.

forvalues nr=9(3)48 {
local x=`nr'-1
local y=`nr'+2
local z=`nr'+3
replace var`x'=var`x'+var`y' if var`nr'=var`z'
}

However, I realised that this was not a good idea. I may try you
program, but decided to go back to the raw data (the database I
presented was the result of manipulation of another database) and find
another solution.
Thanks

Roland


2012/12/8 Nick Cox <[email protected]>:
> It sounds as if you need something like this
>
> rename var1 id
> rename var2 age
> rename var3 sex
> rename var4 foo
> rename var5 bar
> rename var6 frog
>
> local max "<index of highest number variable>"
>
> local i = 1
> foreach j = 7(3)`max' {
>         rename var`j'   number`i'
>         local J = `j' + 1
>         rename var`J'  diagnosis`i'
>         local J = `J' + 1
>         rename var`J' date`i'
>         local ++i
> }
>
> gen long obsno = _n
> reshape long id age sex foo bar frog number date diagnosis , i(obsno)
>
> The loop isn't necessary, just convenient!
>
> Some commands can be shortened in Stata 12. (See -help rename groups-.)
>
> Nick
>
> On Fri, Dec 7, 2012 at 7:16 PM, roland andersson <[email protected]> wrote:
>> I have data on 3574 unique patients. In the datase there are first 5
>> identification variables ,age, sex and so on. Thereafter comes a
>> nomber of variables representing observations. Each observation has
>> three columns - the sequential number of the observation, the content
>> of the observation and the date. The problem is that these observation
>> are in reverse order, ie the last observation comes first and the
>> first observation last in the row. And the number of observations for
>> each patient range from 1 to 44. Some observations have the same date
>> so they have the same sequential number. below is the data. Var 7, var
>> 10 and var 13 are the number of the observation, var 8, 11, and 14 the
>> observation (the diagnosis or intervention) and var 9, 12 and 15 the
>> date of the observation.
>>
>> I want to reverse the order so that the first observation comes in as
>> var 7 etc. I also want to merge observations with the same date with a
>> new combined content. case nr 1 below sholuld thus be 1
>> diverticulitsigmo 15930. Is this possible?
>>
>> Regards
>> Roland Andersson
>>
>>  var7 var8 var9 var10 var11 var12 var13 var14 var15
>> 1 diverticulit 15930 1 sigmo 15930
>> 1 akutiverticulit 16670 1 sigmo 16670
>> 3 akutiverticulit 17126 2 akutiverticulit 16962 1 akutiverticulit 16359
>> 2 akutiverticulit 17019 1 akutiverticulit 17019
>> 1 akutiverticulit 15831 1 resektion 15831
>> 1 akutiverticulit 16129
>> 3 ctbuk 16839 2 sigmo 16838 1 akutiverticulit 16532
> *
> *   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