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
extract variable labels for new variable namesHi there I try to automate my programming as much as possible and one challenge I've come up agains…
Manually installing Blindschemes by Daniel BischofDear Statalisters I admit this is a bit of a non-problem, but I'd like to find a solution nonethele…
Generate balance tableHi, I'm trying to replicate this balance table (as in the picture) using some of the example dataset…
Multinomial logit with sample selectionDear everyone, I am looking for something similar to Heckman selection model/svysemlog with a modi…
Count number of cases if dates are within a certain range (a la statsby)Greetings all, I have single line per observation survival data (4 million lines). Here is a simpli…
Subscribe to:
Post Comments (Atom)
0 Response to invalid syntax when referencing to variable labels in loops
Post a Comment