I have a panel Data from 1995 to 2021 for 14 products. I want to normalize var1 by its value in 2008 across time. How can I do that?
-
Login or Register
- Log in with
* Example generated by -dataex-. For more info, type help dataex clear input float year str6 product float x 2006 "invest" 317.6 2006 "kstock" 2.8 2006 "mvalue" 3078.5 2007 "invest" 391.8 2007 "kstock" 52.6 2007 "mvalue" 4661.7 2008 "invest" 410.6 2008 "kstock" 156.9 2008 "mvalue" 5387.1 2009 "invest" 257.7 2009 "kstock" 209.2 2009 "mvalue" 2792.2 2010 "invest" 330.8 2010 "kstock" 203.4 2010 "mvalue" 4313.2 end format %ty year isid product year bys product: egen val2008= max(cond(year==2008, x, .)) gen wanted= x/val2008
. sort product year
. l, sepby(product)
+----------------------------------------------+
| year product x val2008 wanted |
|----------------------------------------------|
1. | 2006 invest 317.6 410.6 .7735022 |
2. | 2007 invest 391.8 410.6 .9542133 |
3. | 2008 invest 410.6 410.6 1 |
4. | 2009 invest 257.7 410.6 .6276181 |
5. | 2010 invest 330.8 410.6 .8056502 |
|----------------------------------------------|
6. | 2006 kstock 2.8 156.9 .0178458 |
7. | 2007 kstock 52.6 156.9 .3352454 |
8. | 2008 kstock 156.9 156.9 1 |
9. | 2009 kstock 209.2 156.9 1.333333 |
10. | 2010 kstock 203.4 156.9 1.296367 |
|----------------------------------------------|
11. | 2006 mvalue 3078.5 5387.1 .5714577 |
12. | 2007 mvalue 4661.7 5387.1 .865345 |
13. | 2008 mvalue 5387.1 5387.1 1 |
14. | 2009 mvalue 2792.2 5387.1 .5183123 |
15. | 2010 mvalue 4313.2 5387.1 .8006535 |
+----------------------------------------------+
Comment