I'm struggling to come up with a solution for finding if each observation in variable 1 matches ANY of the specified observations in v2.I'm trying to narrow the data to focus on passengers that have arrived on-time at least one time in the data. That way I can look at those passengers' data, even for points when they weren't on time.
I'm trying to pass a numlist to anymatch of the names of the ID's of the passengers that have arrived on time at least one time but I'm getting an error.
"values() invalid -- invalid numlist"
This is my code:
g on_time= passengers if timely==1; // limiting to timely arrivals.
levelsof on_time;
g on_time_levels= r(levels); //unique numlist of passengers with timely arrivals (unsure of this)
g on_time_ever=.;
forvalues i =1/6939 {;
egen tempvariable = anymatch(passengers) if _n==`i',values(on_time_levels);
replace on_time_ever=tempvariable if _n==`i';
drop tempvariable;
};
I am unsure if the levels var I generated is really a numlist. How else can I get a numlist from this variable so I can pass it to anymatch? Or am I just going about this completely wrong?
Thanks!
Related Posts with Using anymatch in a forvalue loop to detect if each value in v1 matches ANY value in v2
eventstudy2 longer event windowHello, I am currently working with eventwindow2 and tried to estimate an event period larger than +…
Instrumental variable analysis for binary dependent and independent variables and binary instrumentHello, I am relatively new to STATA and I am working on a research study investigating medical outc…
Conditional statements to avoid looping error due to missing dataThe loop program runs the regression by SICCode by year. However, it stops in the very initial stage…
Event Study - estimation_window missing values generatedHi all I'm having one problems with event study analysis and I really hope you can help me with this…
Need help with homework!!!Hey, My professor has asked us to work with stata. However, I have no idea about stata at all, I en…
Subscribe to:
Post Comments (Atom)
0 Response to Using anymatch in a forvalue loop to detect if each value in v1 matches ANY value in v2
Post a Comment