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: code to pick one source from many by ids of a panel


From   Sergiy Radyakin <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: code to pick one source from many by ids of a panel
Date   Mon, 22 Jul 2013 19:24:39 -0400

I guess you could reshape your data to long format, generate your
distance variable, sort by it and keep the first observation within
each panelid. Sergiy

On Mon, Jul 22, 2013 at 3:35 PM, László Sándor <[email protected]> wrote:
> Hi,
> Let me describe my problem and work toward a solution, and perhaps
> some -egen- and -reshape- wizards can see ways to do this elegantly or
> write a Speaking Stata or Stata tips one day.
>
> I needed financial data, and to my amazement, different vendors can
> serve different number for as raw data as unadjusted historical
> prices. As I have a reference baseline for some years (from tax
> records), I would be happy to take the source that came the closest
> when available.
>
> My problem is that -egen rowfirst- prioritizes variables in a fixed
> order, I would need a flexible priority that can change across the
> panel (but is constant for all years of each panel).
>
> Is there an elegant way to
> 1. generate distance from a baseline,
> 2. for each panel, generate an identifier of the variable that was closest,
> 3. generate a new variable that selects the series that was the
> closest for the given panel.
>
> For example:
>
> panelid   time   price1    price2    reference   closestprice
> 1            1       1           2           1               1
> 1            2       1           2            .               1
> 2            1       89         75          80             75
> 2            2       86         77          79             77
>
> Thanks,
>
> Laszlo
> *
> *   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