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: add observations
From
Ronnie Babigumira <[email protected]>
To
[email protected]
Subject
Re: st: add observations
Date
Mon, 6 Aug 2012 20:02:35 +0200
Nick,
My hope was that I would get suggestions to get me started, this exchange has done just that so, thank you for the help. It is greatly appreciated.
Best regards,
Ronnie
--
010100100110111101101110011011100110100101100101
On Monday, August 6, 2012 at 7:52 PM, Nick Cox wrote:
> You are correct: it doesn't work as intended. Sorry about that. But on
> looking at your example I see that the implication in your second post
> that there is a single omitted period for each -hcod- is trumped by
> the observation that there can be more than one.
>
> I can't add more on this today given other commitments.
>
> On Mon, Aug 6, 2012 at 6:26 PM, Ronnie Babigumira <[email protected] (mailto:[email protected])> wrote:
> > Thanks Nick,
> >
> > On the rules, thought I'd mentioned them in the first email. Each unit (hcod) should have four periods (pd), 1, 2, 3,and, 4 (hence my use of -fillin-)
> >
> > Otherwise, I think the first part of the code you shared does not appear to be doing what you intended.
> >
> > Best,
> >
> > Ronnie
> >
> > --
> > 010100100110111101101110011011100110100101100101
> >
> >
> >
> >
> > On Monday, August 6, 2012 at 6:35 PM, Nick Cox wrote:
> >
> > > The rules for your data remain cryptic to me. I think you are saying
> > > that for at least some values of -hcod- only three distinct values of
> > > -pd- are observed and the other one is the appropriate replacement.
> > > You could try something like this
> > >
> > > gen obs = ""
> > > bysort hcod (pd) : replace obs = obs + string(pd) if _n == 1 | pd != pd[_n-1]
> > >
> > > gen rep = 4 if obs == "123"
> > > replace rep = 3 if obs = "124"
> > > replace rep = 2 if obs = "134"
> > > replace rep = 1 if obs = "234"
> > >
> > > local N = _N + 1
> > > expand 2
> > > replace pd = rep in `N'/L
> > >
> > >
> > > On Mon, Aug 6, 2012 at 4:21 PM, Ronnie Babigumira <[email protected] (mailto:[email protected])> wrote:
> > > > Thanks Nick,
> > > > This works perfectly for the one unit, however, I have many units and, the missing pd varies from unit to unit. Suggestions on how your solution can be modified to handle this?
> > > >
> > > > My early thinking (and block) was thinking I needed to used -fillin- (and may be levels) however, after sending the email to the list it occurred to me that splitting and then appending the data may do the job. Here is what I have tried.
> > > >
> > > > clear
> > > > input ///
> > > > str8 hcod pd pdt
> > > > 2081115 1 12
> > > > 2081115 3 21
> > > > 2081115 3 11
> > > > 2081115 4 13
> > > > 3031028 1 45
> > > > 3031028 2 21
> > > > 3031028 2 11
> > > > 3031028 3 42
> > > > 3031028 3 13
> > > > 3031028 3 12
> > > > 3061037 2 12
> > > > 3061037 3 45
> > > > 3061096 1 42
> > > > 3061096 1 21
> > > > 3061096 4 45
> > > > 3061096 4 12
> > > > 3061196 1 42
> > > > 3061196 1 45
> > > > 3061196 4 12
> > > > 3061306 1 21
> > > > 3061306 1 45
> > > > 3061306 4 42
> > > > 3061306 4 12
> > > > 3062277 1 41
> > > > 3062277 4 12
> > > >
> > > >
> > > > end
> > > >
> > > > tempfile master
> > > > save `master'
> > > >
> > > > fillin hcod pd
> > > > bysort hcod (pdt): replace pd = pd[_N]
> > > > drop if mi(pdt)
> > > > append using `master'
> > > > sort hcode pd
> > > > list, clean noobs
> > > >
> > > > Ronnie
> > > > --
> > > > 010100100110111101101110011011100110100101100101
> > > >
> > > >
> > > >
> > > >
> > > > On Monday, August 6, 2012 at 3:07 PM, Nick Cox wrote:
> > > >
> > > > > local N = _N + 1
> > > > > expand 2
> > > > > replace pd =4 in `N'/L
> > > > >
> > > > >
> > > > > On Mon, Aug 6, 2012 at 1:25 PM, Ronnie Babigumira <[email protected] (mailto:[email protected])> wrote:
> > > > > > Dear listers,
> > > > > >
> > > > > > I have a dataset that looks like this
> > > > > > hcod pd pdt
> > > > > > 3092285 1 31
> > > > > > 3092285 1 43
> > > > > > 3092285 2 11
> > > > > > 3092285 2 21
> > > > > > 3092285 2 41
> > > > > > 3092285 2 45
> > > > > > 3092285 3 42
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > I would like to add new observations so that I end up with
> > > > > > hcod pd pdt
> > > > > > 3092285 1 31
> > > > > > 3092285 1 43
> > > > > > 3092285 2 11
> > > > > > 3092285 2 21
> > > > > > 3092285 2 41
> > > > > > 3092285 2 45
> > > > > > 3092285 3 42
> > > > > > 3092285 4 31
> > > > > > 3092285 4 43
> > > > > > 3092285 4 11
> > > > > > 3092285 4 21
> > > > > > 3092285 4 41
> > > > > > 3092285 4 45
> > > > > >
> > > > > > 3092285 4 42
> > > > > >
> > > > > >
> > > > > >
> > > > > > Basically, each unit (hcod) should have 4 periods (pd). What we would like to do is add all products (pdt) present in the non-missing periods to the missing period.
> > > *
> > > * For searches and help try:
> > > * http://www.stata.com/help.cgi?search
> > > * http://www.stata.com/support/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/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/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/statalist/faq
* http://www.ats.ucla.edu/stat/stata/