Hello Everyone,
I am new to STATA and would really appreciate your help with a problem I am stuck on. I have a dataset A which looks like this:
id date_time f_id
1 14jan2020 06:34:43 other
1 14jan2020 18:11:13 B
1 14jan2020 20:32:56 C
1 17jan2020 13:45:29 exit
I have a dataset B which looks like this:
date hour f_id weight
08 Jan 20 0 A 0.94
08 Jan 20 1 A 0.92
08 Jan 20 2 A 0.91
.
.
.
.
08 Jan 20 23 A 0.94
08 Jan 20 0 B 0.87
08 Jan 20 1 B 0.89
.
.
08 Jan 20 23 B 0.78
(and so I have weights for each hour of each f_id for each day in that year)
What I want to accomplish is that for every id in dataset A, I want to calculate a variable weighted_sum which for id 1 would look like 49(mins spent in that hour)*(weight for the 18th hour of f_id B on 14th jan 2020) + 60*(weight for the 19th hour of f_id B on 14th jan 2020) + 32*(weight for the 20th hour of f_id B on 14th jan 2020) + 28*(weight for the 20th hour of f_id C on 14th jan 2020) + ....+ 45*(weight for the 13th hour of f_id C on 17th jan 2020).
I am confused about how I should loop to subtract times, get hours, multiply appropriate hourly weights, and adding them. Any help would be greatly appreciated!! Thanks!!
Best,
Joe
Related Posts with Subtracting times across observations and applying weights
Create binary variableHi Statalist, I have question regarding the binary variable. This is the example of my data. Code: …
Hurdle Model: For the selection model can I use Heteroscedastic Probit model instead of a logit/probit model?I am working to estimate a demand model for solar installations. Dependent variable is a count varia…
Combining datasetsStata friends, I've struggled with this one for a while and hope someone can help me. I have two da…
Testing if the mean of a variable has changed significantly over timei am doing an assignment on bank mergers and want to see if there is a significant difference in the…
Condition logit model for discrete choice modelhi, i have difficulty dealing with the conditional model for discrete choice model。 i have two scen…
Subscribe to:
Post Comments (Atom)
0 Response to Subtracting times across observations and applying weights
Post a Comment