Hello wonderful people of statlist. I have a question that is based off of an offshoot of a prior question https://www.statalist.org/forums/for...-and-in-a-loop. It is the last comment I wrote there and I have basically copied here to explain a bit better and get more people to look at it.
So my data let us just say for simplicity has a bunch of observations that represent house lots, a variable lot_id to identify those house lots, and many variables dist_stop1 to dist_stop91 which represent the distance from the house lot to those stops. I started on a loop to try and isolate the observations but I don't know of a way to list out which observations meet my distance criterion for each iteration.
I want to also see which observations are say within 1000 units of each stop represented by the many dist_stopx variables. I was thinking of making a loop that would past which observations are kept. The observations are represented by a variable called lot_id. I have set up a loop but I can't get it right. Could you help, I based it off of what you were so kindly provided earlier.
forval x = 1/91{
drop if dist_stop'x' > 1000
}
My line drops all observations that have a value greater than 1000 for the variable at each iteration. My question would be how do I correctly do this as I feel that dropping would affect every subsequent iteration and I don't know how to get stata to display the observations that match my critereon each iteration.
What I am hoping to see is that for variable x, blah blah remained. So it looks like
dist_stop1
1232, 14321, 534123, 8493, 8445
dist_stop2
8949, 6456, ,8941, 3849,
and so on. The numbers after the dist_stopx would be the value of lot_id for that observation.
Do you know how to help me do that or get stata to past that but it doesn't have to be as clean as I exampled above? I just need variable name and lot_id values next to each other.
Related Posts with Help Building a Loop to tell me which observations meet my Criterion
Missing R-squared from IV regressionQuestion: How can I display/find the missing "within R-squared" from an IV regression? Example of t…
Residuals in a panel data modelHi I am running a regression (using panel data) looking at the effect of income on food consumption …
Longitudinal data - generating variables dependent on observations within each subjectHi everyone, I have longitudinal data (see dataex below). I need to censor each id according to a f…
How can I make a line graph for data from a certain date range?Hello! I'm working with daily time series data with the date originally in the format "01/29/19" (st…
Adding an interaction term into a model or stratifying data , which method is more preferable to analyse interaction terms?Hi Statlists, Hope this post finds you well. May I know why stratification seems to be less prefera…
Subscribe to:
Post Comments (Atom)
0 Response to Help Building a Loop to tell me which observations meet my Criterion
Post a Comment