Hi,
My data is missing values for all days for the year 1996. I would therefore like to use the average value of each day for the year 1997 and 1995 instead to replace it with the missing value for each day of the year 1996. However my code does not seem to work.
I have tried many different versions of this code, and none of them seem to work. In this case the issue is that the if command for the part "save `data95_97' if year == 1995 | year == 1997, replace daymonthavg_*"
is not allowed.
Does anyone have a good idea of how I could improve my code?
Kind regards.
My data is missing values for all days for the year 1996. I would therefore like to use the average value of each day for the year 1997 and 1995 instead to replace it with the missing value for each day of the year 1996. However my code does not seem to work.
Code:
destring year, replace
generate avg_mean = .
unab varlist : debe001-debe126 deni136
foreach var of varlist `varlist' {
egen daymonthavg_`var' = mean(`var'), by(day month year)
}
tempfile data95_97
save `data95_97' if year == 1995 | year == 1997, replace daymonthavg_*
use `data95_97', clear
collapse (mean) mean_value = daymonthavg_*
display "Mean of variables for 1995 and 1997: " `mean_value'
tempfile data96
save `data96', replace: daymonthavg_* if year == 1996
use `data96', clear
replace avg_mean = `mean_value' if year == 1996
is not allowed.
Does anyone have a good idea of how I could improve my code?
Kind regards.

Comment