I am using Stata version 15 on a dataset with about 900,000 observations. I would like to create a lagged variable using xtset command. The challenge is I am having two variables that jointly act as a unique ID hence I can’t use
Code:
xtset code1 code2 year
I am providing some example data for ease in replication.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str3 code1 str2 code2 int(year cvalue) "AAA" "S1" 2010 256 "AAA" "S1" 2011 412 "AAA" "S1" 2012 736 "AAA" "S1" 2013 587 "BBB" "S2" 2010 694 "BBB" "S2" 2011 531 "BBB" "S2" 2012 820 "BBB" "S2" 2013 347 "CCC" "S3" 2010 964 "CCC" "S3" 2011 308 "CCC" "S3" 2012 960 "CCC" "S3" 2013 250 end
0 Response to Creating a lag variable
Post a Comment