I'm trying to refer to the labels of variables (to include these in graph titles) when looping on a group of variables to generate graphs. I've tried several methods and changed several functions to plot graphs, but none of these would work. I've also read many previous posts regarding this topic, but even direct copy and past of the code referring to the value label wouldn't work.
here's the code that calls variable labels in loops that I got from a previous post:
"`:label variable `var'' sample1"
(https://www.statalist.org/forums/for...iables-in-loop)
and here's the full code that I'm using:
local y "teacher volunteer "
foreach var of local y {
splitvallabels `var'
catplot gender `var', ///
percent(gender) ///
var1opts(label(labsize(small))) ///
var2opts(label(labsize(small)) relabel(`r(relabel)')) ///
ytitle("Percent of Respondents by gender", size(small)) ///
title("`:label variable `var'' sample1" ///
, span size(medium)) ///
blabel(bar, format(%4.1f)) ///
intensity(25) ///
asyvars
}
This works, but the title wouldn't show the variable label as the stata reports "invalid syntax."
here's the graph I got:
Array
all good--except for the variable label part that's supposed to be included in the title.
This is a fairly simple graph that looks at the percentage by gender who agree/disagree to the statement that they've participated in the project because they liked the teacher/the volunteer who organized it. However, the variable labels are more useful in titles than the variable names. I want this in a loop because I actually have more than two variables to loop (about 20 in total).
Can somebody help me to figure out how I can correctly refer to the variable labels in the loop? Thanks!
Related Posts with invalid syntax when referencing to variable labels in loops
Generate sum of variables with sequential variables namesHi everyone, I have a data with these sequential variable names. p1_1_1_1 p1_1_1_2 p1_1_1_3 p1_1…
Generate var using sequential variables namesHi everyone, p1_1 p1_2 p1_3 p2_1 p2_2 p2_3 p3_1 p3_2 p3_3 1 1 1 2 2 2 3 3 3 1 1 1 2 2 2 3 3 3 1 1 …
Removing NA Across varI have data in string as shown below data1 data2 NA NA NA NA NA NA NA 8415739 NA 10024002 N 1205788…
Split string variableDear Experts, I want to split the string variable. Please advice. The issue is: I have the respons…
about synth instruction questionhello great master I have a question My stata version is 14 when I perform the instruction, it alway…
Subscribe to:
Post Comments (Atom)
0 Response to invalid syntax when referencing to variable labels in loops
Post a Comment