R stata(11)中逐因素交互的语法是什么?

R stata(11)中逐因素交互的语法是什么?,r,syntax,statistics,stata,interaction,R,Syntax,Statistics,Stata,Interaction,我有两个因子变量,一个编码为数字,另一个编码为字符串。称它们为C和N。我想在回归中包含它们的交互(这将把它们扩展成假人,在R中我将编写代码) lm(y~as.factor(C)*as.factor(N)) 或 在斯塔塔,我想做一些像 xtset C N xtreg y c*N, fe 执行此操作的语法是什么?必须转换为数字的字符串变量。编码是一个选项。然后使用Stata的因子变量表示法(即)。一个无意义的示例: clear all set more off sysuse auto descr

我有两个因子变量,一个编码为数字,另一个编码为字符串。称它们为
C
N
。我想在回归中包含它们的交互(这将把它们扩展成假人,在R中我将编写代码)

lm(y~as.factor(C)*as.factor(N))

在斯塔塔,我想做一些像

xtset C N
xtreg y c*N, fe

执行此操作的语法是什么?

必须转换为数字的字符串变量。
编码
是一个选项。然后使用Stata的因子变量表示法(即
)。一个无意义的示例:

clear all
set more off

sysuse auto
describe
keep price mpg make

encode make, gen(make2)
regress price mpg c.mpg#i.make2
因子变量表示法是在Stata 11中精确引入的

有关详细信息,请键入
帮助因子变量
帮助编码


注意:我没有尝试将R代码转换为Stata。

必须转换为数字的字符串变量。
编码是一个选项。然后使用Stata的因子变量表示法(即
)。一个无意义的示例:

clear all
set more off

sysuse auto
describe
keep price mpg make

encode make, gen(make2)
regress price mpg c.mpg#i.make2
因子变量表示法是在Stata 11中精确引入的

有关详细信息,请键入
帮助因子变量
帮助编码

注意:我没有尝试将您的R代码转换为Stata。

#
xtabond
中不起作用。请参阅Statalist上的类似问题。以下是在Stata中解决实际问题的快捷方法:

webuse abdata
tabulate ind,gen(ind) # industry dummies 
tabulate year,gen(yr) # this is not needed because it is already in the dataset
egen ind_year=group(ind year) # interaction of year and ind or gen ind_year=ind*year works
tabulate ind_year,gen(ind_year) # interaction dummies
xtabond n l(0/1).w  ind2-ind9 yr1977-yr1984 ind_year2-ind_year80
注意:在
R
中,您可以在
Stata
中为
组使用
interactive
#
xtabond
中不起作用。请参阅statistist上的类似问题。以下是在Stata中解决实际问题的快速而肮脏的方法:

webuse abdata
tabulate ind,gen(ind) # industry dummies 
tabulate year,gen(yr) # this is not needed because it is already in the dataset
egen ind_year=group(ind year) # interaction of year and ind or gen ind_year=ind*year works
tabulate ind_year,gen(ind_year) # interaction dummies
xtabond n l(0/1).w  ind2-ind9 yr1977-yr1984 ind_year2-ind_year80

注意:在
R
中,您可以在
Stata

中为
组使用
interactive
,谢谢!不幸的是,它并没有帮助我解决真正的问题:
xtabond yield ss1#i.vl ss6#i.vl ss5#i.vl ss4#i.vl ss3#i.vl ss2#i.vl ss1-ss6#t L2##l#2###i.vl L2########两个代码nd这是什么?R中的PLM不适合删除共线假人不客气。事实上,在发布到站点/论坛(如Stack Overflow)时,简化问题是有用的,但它仍然需要具有代表性。在这种情况下,它看起来离真实事物太远了。谢谢!不幸的是,它最终没有帮助我解决真正的问题:
xtabond yield ss1#i.vl ss6#i.vl ss5#i.vl ss4#i.vl ss3#i.vl ss2#i.vl ss1-ss6 t L1.yield L2.yield,不允许两个健壮的交互
知道如何解决这个问题吗?在R中的PLM不适合删除共线假人。确实,在发布到站点/论坛(如堆栈溢出)时简化这个问题是有用的,但它仍然没有eds必须具有代表性。在这种情况下,它看起来离真实事物太远了。看看你真实问题的答案。看看你真实问题的答案。