Stata 使用grc1leg重新标记

Stata 使用grc1leg重新标记,stata,Stata,我试图在一个插图中显示四个不同的图表。我正在使用社区贡献的命令grc1leg。 但是,如果在每个单独的图形中使用relabel,则命令grc1leg无法识别更改 我的数据示例如下: +---------+----------+------------+----+----+----+----+ | student | matutino | vespertino | p6 | p7 | p8 | p9 | +---------+----------+------------+----+----+--

我试图在一个插图中显示四个不同的图表。我正在使用社区贡献的命令
grc1leg
。 但是,如果在每个单独的图形中使用
relabel
,则命令grc1leg无法识别更改

我的数据示例如下:

+---------+----------+------------+----+----+----+----+
| student | matutino | vespertino | p6 | p7 | p8 | p9 |
+---------+----------+------------+----+----+----+----+
| 1       | 1        | 0          | 1  | 3  | 4  | 3  |
+---------+----------+------------+----+----+----+----+
| 2       | 1        | 0          | 2  | 5  | 1  | 2  |
+---------+----------+------------+----+----+----+----+
| 3       | 0        | 1          | 2  | 2  | 6  | 2  |
+---------+----------+------------+----+----+----+----+
变量
Matutino
是学生是否参加早课的虚拟变量

变量
Vespertino
是学生是否参加下午课程的虚拟变量

变量
p6
指的是问题6,该问题询问学生是否工作,它取两个值:
1
2

变量
p7
询问学生工作了多长时间,需要六个值:
1,2,3,4,5,6

变量
p8
p9
就像
p7

我的数据是以数字形式编码的,但它代表了调查的字符串答案。我想在
x轴
图形中使用字符串名称,而不是数字代码

我的代码如下:

graph bar (percent) matutino (percent) vespertino, over (p6,relabel (1 "Si" 2 "No")) name(p6, replace) title("¿Trabajas actualmente?") nolabel
graph bar (percent) matutino (percent) vespertino, over (p7,relabel (1 "0-1" 2 "1-5" 3 "6-11" 4 "12-24" 5 "más de 24")) name(p7, replace) title ("Tiempo trabajando") legend(off) b1title("Meses")
graph bar (percent) matutino (percent) vespertino, over (p8,relabel (1 "1-3" 2 "4-6" 3 "7-9" 4 "10-12" 5 "13-15" 6 "16-18" 7 "19-21" 8 "22-24" 9 "más de 25")) name(p8, replace) title ("Horas trabajadas a la semana") legend(off) b1title("Horas")
graph bar (percent) matutino (percent) vespertino, over (p9,relabel (1 "Independencia" 2 "Gastos personales" 3 "Continuar estudiando" 4 "Experiencia laboral" 5 "Mantener a la familia" 6 "Ayuda en el negocio familiar") label (labsize(small) angle(45))) name(p9, replace) title ("Motivo para trabajar") legend(off)
grc1leg p6 p7 p8 p9, l1(Porcentaje) legendfrom(p6)
代码分别适用于每个图形,例如:

graph bar (percent) matutino (percent) vespertino, over (p7,relabel (1 "0-1" 2 "1-5" 3 "6-11" 4 "12-24" 5 "más de 24")) name(p7, replace) title ("Tiempo trabajando") legend(off) b1title("Meses")
graph bar (percent) matutino (percent) vespertino, over (p6) name(p6, replace) title("¿Trabajas actualmente?") nolabel
graph bar (percent) matutino (percent) vespertino, over (p7) name(p7, replace) title ("Tiempo trabajando") legend(off) b1title("Meses")
graph bar (percent) matutino (percent) vespertino, over (p8) name(p8, replace) title ("Horas trabajadas a la semana") legend(off) b1title("Horas")
graph bar (percent) matutino (percent) vespertino, over (p9) name(p9, replace) title ("Motivo para trabajar") legend(off)
grc1leg p6 p7 p8 p9, l1(Porcentaje) legendfrom(p6)
当我组合这四个图形但不使用relabel选项时,代码也可以工作,例如:

graph bar (percent) matutino (percent) vespertino, over (p7,relabel (1 "0-1" 2 "1-5" 3 "6-11" 4 "12-24" 5 "más de 24")) name(p7, replace) title ("Tiempo trabajando") legend(off) b1title("Meses")
graph bar (percent) matutino (percent) vespertino, over (p6) name(p6, replace) title("¿Trabajas actualmente?") nolabel
graph bar (percent) matutino (percent) vespertino, over (p7) name(p7, replace) title ("Tiempo trabajando") legend(off) b1title("Meses")
graph bar (percent) matutino (percent) vespertino, over (p8) name(p8, replace) title ("Horas trabajadas a la semana") legend(off) b1title("Horas")
graph bar (percent) matutino (percent) vespertino, over (p9) name(p9, replace) title ("Motivo para trabajar") legend(off)
grc1leg p6 p7 p8 p9, l1(Porcentaje) legendfrom(p6)
我想要的是在同一个插图中有四个图形,但是使用我在每个单独的图形中写下的字符串标签

我也尝试过标签定义选项,但在显示图形时它不起作用。我找到的唯一解决方案是使用字符串名称为每个问题创建新变量。然而,我有154个问题,我认为应该有一个更简单的方法


交叉张贴

重新标记不起作用,因为
grc1leg
在合并每个图形之前会再次绘制它们

处理此问题的最简单方法是在不使用
relabel
选项的情况下组合四个图形,然后按如下方式对生成的图形进行后处理:

local lbl 1-3 4-6 7-9
tokenize `lbl'

forvalues i = 1 / 3 {
    gr_edit .plotregion1.graph3.grpaxis.edit_tick `i' ///
    `.Graph.plotregion1.graph3.grpaxis.major.dlg_tickpos[`i']' ///
    `"``i''"', tickset(major)
}

其思想是定义一个本地宏
lbl
,该宏保存标签,然后循环标记位置以重新标记标签。在这种情况下,上述代码会修改第三个图形,但其余图形的处理过程是相同的。

重新标记不起作用,因为
grc1leg
会在合并它们之前再次绘制每个图形

处理此问题的最简单方法是在不使用
relabel
选项的情况下组合四个图形,然后按如下方式对生成的图形进行后处理:

local lbl 1-3 4-6 7-9
tokenize `lbl'

forvalues i = 1 / 3 {
    gr_edit .plotregion1.graph3.grpaxis.edit_tick `i' ///
    `.Graph.plotregion1.graph3.grpaxis.major.dlg_tickpos[`i']' ///
    `"``i''"', tickset(major)
}

其思想是定义一个本地宏
lbl
,该宏保存标签,然后循环标记位置以重新标记标签。在这种情况下,上面的代码修改了第三个图形,但其余图形的处理过程是相同的。

它工作得非常好!!非常感谢你!!这将在显示我的工作成果时对我有很大帮助!!:)它工作得很好!!非常感谢你!!这将在显示我的工作成果时对我有很大帮助!!:)