In the current project I'm working on, I keep updating a list of variables. I would like to use the list of variables I create in 1 dta file to rename the variables in a second dta file. The number of variables changes as I progress in the project.
Here is the list of variables I have in the 1st file:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str8 DATATYPE "400E" "897E" "BETA" "DY" "IBNOSH" "MSCA" "MTBV" "MV" "P" "PI" "PTBV" "RI" "VO" "VOL" "WC01001" "WC01151" "WC01551" "WC02001" "WC02005" "WC02201" "WC02999" "WC03051" "WC03051A" "WC03061" "WC03062" "WC03063" "WC03101" "WC03151" "WC03251" "WC03255" "WC04049" "WC04821" "WC04828" "WC04900" "WC05301" "WC05302" "WC05476" "WC05491" "WC05508" "WC06615" "WC06699" "WC08311" "WC08326" "WC08621" "WC08806" "WC09802" "WC18226" end
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input long unit_id int time double(data1 data2 data3 data4 data5 data6 data7 data8 data9 data10) 1 1 .2647 .9581 . 1.16 62.144 . 2.21 11821.59 190.23 772.5 1 2 .2648 1.0914 . 1.16 62.199 . 2.2 11759.45 189.23 768.4 1 3 .2509 1.0191 . .97 62.501 . 2.64 14152.11 227.53 924 1 4 .2686 1.081 . .83 62.501 . 3.08 16487.64 263.8 1071.3 1 5 .2672 1.0706 . .79 62.501 . 3.27 17477.64 279.6399 1135.6 end label values unit_id unit_id label def unit_id 1 "130062", modify
Code:
ui ds loc lastvar: word `c(k)' of `r(varlist)' rename (data1-`lastvar') (_400E _897E BETA DY IBNOSH MSCA MTBV MV P PI PTBV RI VO VOL WC01001 WC01151 WC01551 WC02001 WC02005 WC02201 WC02999 WC03051 WC03051A WC03061 WC03062 WC03063 WC03101 WC03151 WC03251 WC03255 WC04049 WC04821 WC04828 WC04900 WC05301 WC05302 WC05476 WC05491 WC05508 WC06615 WC06699 WC08311 WC08326 WC08621 WC08806 WC09802 WC18226 WC08621 WC08806 WC09802 WC18226)
0 Response to Use list of variables in dta file to rename variable in other dataset
Post a Comment