Hello, I am using Stata 16.0, I have a dataset with many variables concerning election results.
I have some variables that list the amount of votes certain parties got, and some variables
that list the share of the votes that such parties got in the election.
In this short example I have two parties, then for each party I have a variable
called S_percent_NAMEPARTY (share of votes), and a variable called S_Votes_NAMEPARTY (total amount of votes), so that
I have 2*2=4 variables.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str34 comune_oggi float S_percent_M5S double S_Votes_M5S float S_percent_FDI double S_Votes_FDI "Milano" .14763483 99395 .01660604 11180 end
Code:
. list +------------------------------------------------------+ | comune~i S_per~5S S_Vot~5S S_perc~I S_Vote~I | |------------------------------------------------------| 1. | Milano .1476348 99395 .016606 11180 | +------------------------------------------------------+
to label these variables with a loop which should work in this way :
My objective is to generate a loop that works in this way :
Code:
label variable S_percent_NAMEPARTY "% NAMEPARTY" label variable S_votes_NAMEPARTY "NAMEPARTY TOT VOTES"
This was my attempt :
Code:
. foreach x in M5S FDI{ 2. label variabel S_Votes_`x' "`x' tot votes" 3. label variabe S_Votes_`x' " % `x'" 4. } invalid syntax r(198);
0 Response to How to loop variables' labels in stata
Post a Comment