Hello there ! I am hoping to get a reply for this since I am struggling with it for quite some time today.
What i want to do basically is to create a new variable that will give the mean of the past 5 observations of another variable. So for instance for the data i post below I want to have variable that provides the average temperature (Temp_G~g) the past five minutes (i.e Temp_G~g_n - Temp_G~g_n-4) . Of course at certain time points I have missing data for temperature.
I noticed that it is recommended in other posts to sum the past 5 observations and then divide by the number of past non-missing observations, yet i still cant get the code quite right. Can someone help me with this !??
Thank you,
George
+--------------------------------+
| Date_Time2 Temp_G~g |
|--------------------------------|
1. | 27/05/2019 09:47:00 25.9 |
2. | 27/05/2019 09:48:00 26.0 |
3. | 27/05/2019 09:49:00 26.0 |
4. | 27/05/2019 09:50:00 26.1 |
5. | 27/05/2019 09:51:00 26.1 |
|--------------------------------|
6. | 27/05/2019 09:52:00 26.2 |
7. | 27/05/2019 09:53:00 26.1 |
8. | 27/05/2019 09:53:59 26.1 |
9. | 27/05/2019 09:55:00 26.1 |
10. | 27/05/2019 09:56:00 26.1 |
|--------------------------------|
11. | 27/05/2019 09:57:00 26.2 |
12. | 27/05/2019 09:58:00 26.1 |
13. | 27/05/2019 09:59:00 26.1 |
14. | 27/05/2019 10:00:00 26.1 |
15. | 27/05/2019 10:01:00 26.3 |
|--------------------------------|
16. | 27/05/2019 10:01:59 26.3 |
17. | 27/05/2019 10:03:00 26.4 |
18. | 27/05/2019 10:04:00 26.3 |
19. | 27/05/2019 10:05:00 26.2 |
20. | 27/05/2019 10:06:00 26.2 |
+--------------------------------+
Related Posts with Averaging observations within a column having missing values
DHS Data - Sample weights and stratification - Nigeria 2008 and 2018Dear all, Currently I am using DHS data in combination with Stata for the first time. I intend to e…
How to Run Random Forest for Time-Series DataHi, I am writing this post to ask whether there is any Stata command (or doing manually) to apply t…
Generating means for a region using only one observation per householdHi, I have a question regarding generating averages. I have one column with a unique Houshold ID fo…
Unit root in variablesFor my study I am writing a research paper for the first time and I seem to be having a problem with…
Main effect in logistic regression with interactionHello, I have a logistic regression model with interaction term (variable##sex). Variable is catego…
Subscribe to:
Post Comments (Atom)
0 Response to Averaging observations within a column having missing values
Post a Comment