Quantcast
Channel: Statalist
Viewing all articles
Browse latest Browse all 73258

Using Averages to Fill Missing Values

$
0
0
Hello,

I have a pannel data that looks like this:
ID t OTIF
1 1 1
1 2 .
1 3 .
1 4 1
1 5 .
1 6 1
2 1 0.5
2 2 0.7
2 3 .
2 4 1
2 5 0.8
2 6 .
Where ID is the individual ID, t is my time variable (actually 1-24, representing 2 years) and OTIF is average OTIF for that individual in that month.

I'm trying to fill in the gaps (null values) in OTIF, by creating OTIF_ADJ... using the average from last 3 months would be perfect, but I don't think it's even possible because situations like ID=1 where I don't have data from 3 months earlier to use.

So I ended up thinking about using average OTIF, using this code:

Code:
bysort ID (t): generate OTIF_ADJ = OTIF if OTIF !=.
bysort ID (t): replace OTIF_ADJ = mean(OTIF) if OTIF_ADJ==.
But it's not working.

I appreciate any help I can get!

Thanks!

Viewing all articles
Browse latest Browse all 73258

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>