楼主: dxystata
3541 17

[一般统计问题] 【讨论】统计变量的个数 [推广有奖]

11
sungmoo 发表于 2013-6-6 09:06:31
变量很多,-2这种写法不实用
看你的“之间”怎么理解。若含首尾变量,不必减2。

12
蓝色 发表于 2013-6-6 10:22:27
. sysuse auto
(1978 Automobile Data)

. des

Contains data from /Applications/Stata/ado/base/a/auto.dta
  obs:            74                          1978 Automobile Data
vars:            12                          13 Apr 2011 17:45
size:         3,182                          (_dta has notes)
--------------------------------------------------------------------------------------------------------------------------
              storage  display     value
variable name   type   format      label      variable label
--------------------------------------------------------------------------------------------------------------------------
make            str18  %-18s                  Make and Model
price           int    %8.0gc                 Price
mpg             int    %8.0g                  Mileage (mpg)
rep78           int    %8.0g                  Repair Record 1978
headroom        float  %6.1f                  Headroom (in.)
trunk           int    %8.0g                  Trunk space (cu. ft.)
weight          int    %8.0gc                 Weight (lbs.)
length          int    %8.0g                  Length (in.)
turn            int    %8.0g                  Turn Circle (ft.)
displacement    int    %8.0g                  Displacement (cu. in.)
gear_ratio      float  %6.2f                  Gear Ratio
foreign         byte   %8.0g       origin     Car type
--------------------------------------------------------------------------------------------------------------------------
Sorted by:  foreign

. d price-foreign

              storage  display     value
variable name   type   format      label      variable label
--------------------------------------------------------------------------------------------------------------------------
price           int    %8.0gc                 Price
mpg             int    %8.0g                  Mileage (mpg)
rep78           int    %8.0g                  Repair Record 1978
headroom        float  %6.1f                  Headroom (in.)
trunk           int    %8.0g                  Trunk space (cu. ft.)
weight          int    %8.0gc                 Weight (lbs.)
length          int    %8.0g                  Length (in.)
turn            int    %8.0g                  Turn Circle (ft.)
displacement    int    %8.0g                  Displacement (cu. in.)
gear_ratio      float  %6.2f                  Gear Ratio
foreign         byte   %8.0g       origin     Car type

. return list

scalars:
            r(changed) =  0
              r(width) =  43
                  r(k) =  12
                  r(N) =  74

. d price-mpg

              storage  display     value
variable name   type   format      label      variable label
--------------------------------------------------------------------------------------------------------------------------
price           int    %8.0gc                 Price
mpg             int    %8.0g                  Mileage (mpg)

. return list

scalars:
            r(changed) =  0
              r(width) =  43
                  r(k) =  12
                  r(N) =  74







为什么这个r(k)是不变的
难道必须只剩下需要统计的变量吗


已有 1 人评分学术水平 热心指数 信用等级 收起 理由
h3327156 + 5 + 5 + 5 好的质疑

总评分: 学术水平 + 5  热心指数 + 5  信用等级 + 5   查看全部评分

13
dxystata 发表于 2013-6-6 10:53:32
蓝色 发表于 2013-6-6 10:22
. sysuse auto
(1978 Automobile Data)
问题就在这里。

14
dxystata 发表于 2013-6-6 11:00:48
sungmoo 发表于 2013-6-6 09:06
看你的“之间”怎么理解。若含首尾变量,不必减2。
x1 x2 x3 m n a b c x y z n1 j1 k1 o 统计b-y之间变量的个数

15
dxystata 发表于 2013-6-6 11:03:20
h3327156 发表于 2013-6-6 09:01
其实我觉得 sungmoo 的方法不错,
我个人比较偏好。
可行,但需要对数据集进行操作!个人不推荐!
其实我的方法和hplcdadong类似,用两句就可以实现。

16
h3327156 发表于 2013-6-6 11:13:07
dxystata 发表于 2013-6-6 11:03
可行,但需要对数据集进行操作!个人不推荐!
其实我的方法和hplcdadong类似,用两句就可以实现。
喔!
其实,这样也是两句搞定阿!

sysuse auto
qui d price-mpg,varlist
di wordcount(r(varlist))
已有 2 人评分经验 论坛币 学术水平 热心指数 信用等级 收起 理由
Sunknownay + 3 + 3 + 3 热心帮助其他会员
dxystata + 20 + 100 + 1 + 1 鼓励积极发帖讨论

总评分: 经验 + 20  论坛币 + 100  学术水平 + 4  热心指数 + 4  信用等级 + 3   查看全部评分

17
sungmoo 发表于 2013-6-6 14:25:28
可行,但需要对数据集进行操作!个人不推荐!
若变量名较长,且变量数较多,从而字符串长度(连空格)超过244个,怎么办?

*附:若要“很通用”(直接以varlist为操作对象),个人以为以下足够了(虽然4步,生成结果其实只用3步):

foreach v of var price-trunk{
loc s=`s'+1
}
* n di `s'

(前面的思路,其实一直不想用“以宏生字符串”的方法)
已有 4 人评分经验 论坛币 学术水平 热心指数 信用等级 收起 理由
Sunknownay + 3 + 3 + 3 热心帮助其他会员
sakiny136 + 1 + 1 + 1 精彩帖子
h3327156 + 5 + 5 + 5 顶礼~~~~~~~~~~~~~~~~
dxystata + 20 + 100 + 1 + 1 鼓励积极发帖讨论

总评分: 经验 + 20  论坛币 + 100  学术水平 + 10  热心指数 + 10  信用等级 + 9   查看全部评分

18
hs4601 发表于 2013-12-15 16:20:49

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2026-1-30 18:36