Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: identifying most recent occurrence (line) where value of variable==X in stata

From   "Alison El Ayadi" <>
To   <>
Subject   st: identifying most recent occurrence (line) where value of variable==X in stata
Date   Wed, 29 Aug 2012 14:10:29 -0400

Hello - 

I am working with a vertical dataset that is essentially tracking blood loss across time for a group of ob patients.  One important variable for cleaning the data is change in drape (which indicates that the cumulative increase should stop).  Because the data is also tracking other variables, this information is not always recorded on the same line that the blood loss is being recorded on.  I would like to generate a variable that tells me the line number of the most recent drape change. but am having trouble figuring that out.  I have used commands in the past such as L. and have seen information online about how to id the first and last occurrences conditionally, but nowhere have I found it possible to condition the skip on the value of the prior variable.  This is necessary because I am not sure how many lines are in between the index line and the line where I would like to extract the data from, and this will vary by line.

In a nutshell, I would like each line to read:
id, line number, blood loss reported on that line, drape change reported on that line, last line number that drape change was reported (or missing if none prior).

Does anyone have any ideas? 

Thank you so much.

*   For searches and help try:

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