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]

st: code to pick one source from many by ids of a panel


From   László Sándor <[email protected]>
To   [email protected]
Subject   st: code to pick one source from many by ids of a panel
Date   Mon, 22 Jul 2013 15:35:26 -0400

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/


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