如何在stata或r中拟合具有多级自变量的多项逻辑回归模型

问题描述 投票:0回答:1

我的旅行数据包括一个人选择特定的交通方式(例如汽车)而不是其他选项(例如公共汽车、飞机和火车)并为他行驶的距离支付一定的价格。每行代表一个人以他们选择的模式进行的一次旅行。 宽格式的数据如下所示:

* Define variables and add data input str15 Mode Mode_id Price Distance Car 1 4.5 109 Train 2 2.1 34 Bus 3 3.3 14 Plain 4 8 150 Car 1 5 20 end * Display the dataset list

我加入了另一个区级社会经济变量的数据集,更新后的数据如下:

* Define the dataset input str15 District District_id str10 Mode Mode_id Price Distance Income Praha 1 1 "Car" 1 4.5 109 200 Praha 1 1 "Train" 2 2.1 34 200 Praha 2 2 "Bus" 3 3.3 14 300 Praha 1 1 "Plain" 4 8 150 200 Praha 2 2 "Car" 1 5 20 300 end * Save the dataset save "Trips_Districts.dta", replace

现在我想用替代的特定自变量“价格”和“距离”以及嵌套在第一层(即地区)的另一组自变量“收入”和“教育”来预测人们的选择偏好模式。

长格式重塑后的数据如下所示:

* Define variable names and data input str10 District str10 District_id Person_id str10 Mode Choice Price Distance Income "Praha 1" 1 1 "Car" 1 4.5 109 200 "Praha 1" 1 1 "Train" 0 . 200 "Praha 1" 1 1 "Bus" 0 . 200 "Praha 1" 1 1 "Plane" 0 . 200 "Praha 1" 1 2 "Train" 1 2.1 34 200 "Praha 1" 1 2 "Car" 0 . 200 "Praha 1" 1 2 "Bus" 0 . 200 "Praha 1" 1 2 "Plane" 0 . 200 "Praha 2" 2 3 "Bus" 1 3.3 14 300 "Praha 2" 2 3 "Plane" 0 . 300 "Praha 2" 2 3 "Car" 0 . 300 "Praha 2" 2 3 "Train" 0 . 300 "Praha1" 1 4 "Plane" 1 8 150 200 "Praha1" 1 4 "Car" 0 . 200 "Praha1" 1 4 "Train" 0 . 200 "Praha1" 1 4 "Bus" 0 . 200 "Praha 2" 1 5 "Car" 1 20 21 300 "Praha 2" 1 5 "Train" 0 . 300 "Praha 2" 1 5 "Bus" 0 . 300 "Praha 2" 1 5 "Plane" 0 . 300 end * Save the dataset save "Trips_Districts_Final.dta", replace

问题1:除了所选模式之外,我没有其他模式的价格和距离信息。

任何将我的宽数据重塑为 stata 或 r 中的长格式的模型推荐和数据代码都将受到高度赞赏。

提前谢谢您。

r logistic-regression multinomial mlogit
1个回答
1
投票

关于重塑为长格式,您最近提供了解决方案这里

关于分析,我在这里看不到足够的数据来创建任何统计模型。我认为你只能创建一些图(例如,使用 ggplot2)。

© www.soinside.com 2019 - 2024. All rights reserved.