Crosspost from Stackoverflow.
I am using Stata 17 on a Windows. I have data in two different datasets. The default dataset is in the .dta format and is cross-section of a sample in year X. The event dataset is imported through an excel file and is a series of events in the same year. I am just interested in the location information of the events.
For each event in the events frame I want to create a two new variables for the location variables (latitudeevent1, longitudeevent1, latitudevent2, longitutdeevent2, etc.) in my default frame. Because the list of events is long, I would like to automate this and not do it manually. The ultimate goal is to compute the distance for each event from the location of the person.
My general idea is to reshape the events data from long to wide leaving me with just one row. The problem is that reshape needs a unique identifier i which leaves me with a table with more than one row. The second problem is accessing the data in the events frame from the default frame. This is problematic because frval needs a linked dataframe which is not possible and frame put [varlist] in [if], into(*newframename*) only works if you put the data into a new frame.
I am using Stata 17 on a Windows. I have data in two different datasets. The default dataset is in the .dta format and is cross-section of a sample in year X. The event dataset is imported through an excel file and is a series of events in the same year. I am just interested in the location information of the events.
Code:
set obs 10 gen iid = _n gen latitude_i = runiform() gen longitude_i = runiform() frame create events frame change events set obs 5 gen eventid = _n gen latitude = runiform() gen longitude = runiform()
Code:
frame change default gen latitude1 = latitude from eventid = 1 in frame events gen longitude1 = longitutde from eventid = 1 in frame events gen latitude2 = latitude from eventid = 2 in frame events gen longitude2 = longitude from eventid = 2 in frame events

Comment