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
How do I reference an estimate after lincom?Hi Everyone: I know there must be a simple solution to this but I haven't found it. I thought that u…
Two questions on fixed effects in stataHello, Can someone please help me understand two issues I have? I am doing a gravity model with pa…
Calculating the mean of categories of a variable created using -egen, cut()-Can someone kindly explain how I can calculate the mean of each wealth category by race or other cha…
Dropping Observations and Creating Fertility VariableQuestion 1: I am using two fertlity variables- age at first intercourse (var name: age1stsex) and a…
Deleting files from folder based on sting conditionHello! I am seeking your help with the following task. Say, I have a folder called Files that conta…
Subscribe to:
Post Comments (Atom)
0 Response to Subtracting times across observations and applying weights
Post a Comment