Suppose I have a panel data with 2 firms and each firm has 6 observations of variable called y

id y

1 1

1 2

1 3

1 4

1 5

1 6

2 6

2 5

2 4

2 3

2 2

2 1

I would like to transform the variables as follows (assign the same y every three observations based on the first observation of y at the 1st, 4th observation etc)

id y

1 1

1 1

1 1

1 4

1 4

1 4

2 6

2 6

2 6

2 3

2 3

2 3

I know how to do it using other software using a for loop but couldn't figure out a way to do it in STATA, could someone help me with it? Thanks a lot!!

id y

1 1

1 2

1 3

1 4

1 5

1 6

2 6

2 5

2 4

2 3

2 2

2 1

I would like to transform the variables as follows (assign the same y every three observations based on the first observation of y at the 1st, 4th observation etc)

id y

1 1

1 1

1 1

1 4

1 4

1 4

2 6

2 6

2 6

2 3

2 3

2 3

I know how to do it using other software using a for loop but couldn't figure out a way to do it in STATA, could someone help me with it? Thanks a lot!!

## Comment