version: 1.0
help for autofill Oct. 1st, 2021

Title

autofill - Fill all kinds of missing values based on existing data

Syntax

autofill varlist , forward|backward [groupby(varname)]

varlist - The varlist whose data include missing value.

forward|backward - You need choose one from the options "forward" and "backward". If you choose "forward", the program will use the existing values to replace the missing values before them. If you choose "backward", the program will use the existing values to replace the missing values after them.

groupby(varname) - Select a variable and group it according to its value. The observation with different values of this variable will be marked as different groups. Missing values in one group will not be replaced by existing values in other groups.

Description

Autofill program makes it easy to fill in missing values with existing values in the data. It applies to all types of missing values in the Stata and can operate on lots of variables simultaneously. In addition, it provides a way to fill the missing values by group.

Example

You can creat the following dataset.

I | T | X | Y

---+---+---+---

a | 1 | . | .

a | 2 | 5 | .

a | 3 | . | 4

b | 1 | 3 | .

b | 2 | . | 5

a,b is two individuals, T=1,2,3 are different times, and X,Y is two variable values of individuals at different times.

autofill X Y, backward - You will get the following dataset.

I | T | X | Y

---+---+---+---

a | 1 | . | .

a | 2 | 5 | .

a | 3 | 5 | 4

b | 1 | 3 | 4

b | 2 | 3 | 5

autofill X Y, forward - You will get the following dataset.

I | T | X | Y

---+---+---+---

a | 1 | 5 | 4

a | 2 | 5 | 4

a | 3 | 3 | 4

b | 1 | 3 | 5

b | 2 | . | 5

autofill X Y, forward groupby(I) - You will get the following dataset.

I | T | X | Y

---+---+---+---

a | 1 | 5 | 4

a | 2 | 5 | 4

a | 3 | . | 4

b | 1 | 3 | 5

b | 2 | . | 5

After using groupby(I), the X value of b at time T=1 does not replace the X value of the previous observation(a at time T=3).

Author

Xia P.S.

University of Chinese Academy of Sciences

Email: xia_ps@yeah.net