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: Panel data - Finding a match for an observation in one variable, from among some values of a different variable, in a previous time period


From   Rahul Ahluwalia <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: Panel data - Finding a match for an observation in one variable, from among some values of a different variable, in a previous time period
Date   Tue, 27 Nov 2012 16:15:46 +0530

Dear Statalist
First of all, thank you. I've found many of the solutions posted here to be very helpful. I'll try and explain my current problem as best I can. I have some very inefficient and inelegant code that gets me what I need, but I would appreciate knowing the 'proper' way of doing this.

I have the following variables : year, id, comp_value, match_value, batch, test_flag. The data is in an unbalanced panel using year and id. test_flag indicates when an id enters the panel. I need to do the following - whenever test_flag == 1, I need to check that observation's match_value with the comp_value of all observations in the previous year that belong to the same batch and make note of the id. e.g 


year id comp_value  match_value batch test_flag   match_id
1999  1   505	             76     9       0          .
1999  2   500	             89     8       0		.
1999  3   505	             98     8       0		.
2000  1   55	             10     9       0		.
2000  2   500	             40     9       0		.
2000  4   500	             505    8       1          .
2001  5   0			55	8	  1		.

The code I need would compare the match_value of id 4, year 2000, i.e 505, check it against the comp_value of all observations from year 1999 and the same batch(8) and change match_id to 3. The code would also check year 2001 and id 5 but would not cause any change in match_id. What would be really great is if another variable, say, match_count would tell me if there are multiple matches.

Regards
Rahul

*
*   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