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
FIXED EFFECT MODEL, small saple size.Dear all, I am regressing the impact of Netflix subscriptions on theatrical admissions in 16 countri…
xtgcause interpretationI have run a test for Granger non-causality in heterogeneous panels using the procedure proposed by …
Renaming variable labels to be one number lower (Q141 to Q140)Good Morning, I am looking to rename my variables so that the numeric value is one less than what i…
Concentration curves of a dichotomous variableHi, I am new to the forum and stata itself. I need help in drawing a concentration curve. I am tryin…
Export Regressions to Different Sheets in Same Excel Doc.I have been trying to figure out a way to automate my regression output such that each set of regres…
Subscribe to:
Post Comments (Atom)
0 Response to Subtracting times across observations and applying weights
Post a Comment