I am interested in renaming several variables by its label (see an example below), however, after trying the code suggested by Nick Cox
in the following post
HTML Code:
https://www.statalist.org/forums/forum/general-stata-discussion/general/1367292-rename-variable-with-its-own-label
Code:
. foreach v in IngresosdeexplotaciónmilEUR S T U V W X Y Z AA AB AC AD AE AF AG AH AI AJ > AK AL AM AN { 2. local lbl : var label `v' 3. local lbl = strtoname("`lbl'") 4. rename `v' `lbl' 5. } variable Ingresos_de_explotación mil_EUR already defined r(110);
My interest is to rename using the first two words and the year "ingresos_explotacion_year" (even though using the whole label is not a problem) but cannot figure out how to do it.
Have you got any suggestions?
If instead of using the label (because label exceeds max allowed), is it possible to do it with a loop? I am worried of having to do it for nearly more than 400 variables.
Thanks for the help.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str17(IngresosdeexplotaciónmilEUR Ingresos_de_explotación mil_EUR T U V W X Y Z AA AB AC AD AE AF AG AH AI AJ AK AL AM AN) data width (259 chars) exceeds max linesize. Try specifying fewer variables r(1000);
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str17(S T U V W X Y Z AA AB AC AD AE AF AG AH AI AJ AK AL AM AN) "n.d." "22595593" "19651680" "16161180" "18874398" "22465185" "24287783" "25537175" "20152095" "16514555" "12807244" "18952916" "18457817" "18048055" "15872465" "12471983" "10935400" "10482412" "11555475" "12947750" "9856050" "8521250" "n.d." "22323170" "21072429" "19823515" "19077481" "18458967" "18062450" "17552041" "16476333" "15270146" "14428567" "14308686" "13008010" "11305219" "9619766" "8160861" "6714947" "5383831" "4190484.77" "3130177.01" "2532272.11" "2024728.69" "n.d." "12546822" "12622285" "11767670" "12382735" "12409513" "12064764" "12007707" "10451069" "8734069" "7340616" "5978153" "4429450" "3742321" "2913928" "2251028" "1654744" "1376792" "1129545" "959650" "586620" "35346.44839" "n.d." "11551899" "11732409" "11001619" "10649650" "10025200" "9783995" "9971343" "10855490" "11446045" "11587826" "11957626" "12638574" "12276595" "11603123" "10671343" "9822262" "8824087" "8127077" "7504480" "6819020" "6108030" "n.d." "10495100" "10013400" "9023100" "8805300" "8007400" "6927300" "6499800" "5635900" "5073300" "4492500" "5183900" "5958647" "5879585" "5530476" "6175243" "5892629" "6001484" "6180221" "6622040" "6019590" "5149540" "n.d." "8161218" "8120635" "7555509" "7464915" "7447843" "7453987" "7610992" "8720877" "8965750" "9241473" "9963897" "9833661" "9291333" "9118136" "8573989" "7846555" "6935452" "6817715" "6877750" "3054490" "3001930" "n.d." "7621970" "8338006" "8591648" "7087795" "5403570" "4633775" "4621277" "5069761" "5029228" "4628056" "4095911" "4648421" "4497158" "5199066" "5564046" "5600126" "4907792" "5045490" "5582785.22" "5428407.17" "4807401.5" "n.d." "7217991" "7226263" "6554127" "6113094" "7818886" "8684904" "n.d." "n.d." "1310568" "1397581" "1001815" "2164422" "1356" "1810" "1288" "3586" "2393" "2409" "3100" "3608.19" "4127.939" "n.d." "6830814" "5446768" "4619628" "5404399" "6692432" "6862128" "6799981" "6964958" "5361728" "4351212" "6451078" "5603375" "5370269" "4910238" "3740331" "3302357" "2831875" "3154059" "3658820" "2321750" "2088129" "n.d." "4865000" "4530000" "4238000" "4363000" "3985000" "4004000" "4711000" "4807000" "4710008" "n.d." "n.d." "n.d." "n.d." "n.d." "n.d." "n.d." "n.d." "n.d." "n.d." "n.d." "n.d." end
0 Response to failing to rename a variable by its label
Post a Comment