I am using Stata 15.1. I have nested panel in my data. I am struggling to generate panel row ids. Below is the structure of my data. I want to generate the last column. Can someone suggest how to go about it.

Best, Shekhar
comp_id year sub_panel_id panel_id new_id
1209 1995 . 1 -18
1209 1996 . 2 -17
1209 1997 . 3 -16
1209 1998 . 4 -15
1209 1999 . 5 -14
1209 2000 . 6 -13
1209 2001 . 7 -12
1209 2002 . 8 -11
1209 2003 . 9 -10
1209 2004 . 10 -9
1209 2005 . 11 -8
1209 2006 . 12 -7
1209 2007 . 13 -6
1209 2008 . 14 -5
1209 2009 . 15 -4
1209 2010 . 16 -3
1209 2011 . 17 -2
1209 2012 . 18 -1
1209 2013 0 19 0
1209 2014 1 20 1
1209 2015 2 21 2
1209 2016 3 22 3
1209 2017 4 23 4
1209 2018 . 24 5