楼主: xueyuan456
54829 88

[数据管理求助] 求助:选分组配对用循环语句OR PSMATCH2?   [推广有奖]

41
sungmoo 发表于 2012-4-14 04:42:14
无尘第二 发表于 2012-4-13 22:59
sungmoo,run这个程序会陷入死循环了………………
就你给的match4.dta,可以运行出结果

42
qjq 发表于 2012-4-16 10:48:02
sungmoo 发表于 2012-3-24 15:31
*year与stkcd的各种组合应是唯一的(或者说,它们可以用来定义panel data)。若不是,可用duplicates d ...
sungmoo, you are so great! the modified program is perfect!

43
无尘第二 发表于 2012-4-17 20:33:09
谢谢sungmoo!可以运行的,加一条 “set more off”更加方便.

44
hnsyxs 在职认证  发表于 2012-6-23 00:02:02
无尘第二 发表于 2012-2-19 11:34
/*下面的程序是对match1.dta中的所有观测值都寻找匹配样本(即sp=1的样本与sp=1的样本配对),而要求是针对其 ...
“针对其中sp=1的公司,寻找sp=0(即配对样本必须sp=0)”
你好 请问以上这条件在你发的程序中体现在哪儿呢?

45
hnsyxs 在职认证  发表于 2012-6-23 00:30:37
sungmoo 发表于 2012-2-23 08:03
*稍微调整一下(结果不变。补充:若mat值只出现一次,则原数据无匹配可能;若mat值重复两次以上,则原数据有 ...
你好,请问为什么运行你的程序,会出现以下问题:

. expandcl s if !fenlei,cl(year stkcd) gen(g)
no room to add more observations
    An attempt was made to increase the number of observations beyond what is currently possible.  You have the following alternatives:

     1.  Store your variables more efficiently; see help compress.  (Think of Stata's data area as the area of a rectangle; Stata can trade off
         width and length.)

     2.  Drop some variables or observations; see help drop.

     3.  Increase the amount of memory allocated to the data area using the set memory command; see help memory.
该怎么解决?

46
michaelniu 发表于 2012-7-10 16:39:13
sungmoo 发表于 2012-4-13 09:00
use match4.dta, clear
bys year ind sp (stkcd):g exp=_n if sp
bys year ind :egen s=max(exp)
看了sungmoo对本贴问题的解答,很受启发,现在使用数据match4学习时,遇到一个问题,使用stata12运行本程序后,发现总样本为181家[见附件],有样本配对成功,请指导一下。
另外:下面这段程序的目的是什么,没太看明白。
sort q stkcd
count if q<.
loc m=r(N)
forv i=1/`m'{
loc v=stkcd[`i']
replace q=. if stkcd==`v'&_n>`i'&!sp
}
我大致的理解是:如果是本证券公司,序号大于本公司,且SP!=1,把赋值q=.
序号小于本公司的公司如何处理呢?

初学stata,问题可能比较初级,请多包涵。

match4_1.zip
下载链接: https://bbs.pinggu.org/a-1142702.html

2.55 KB

本附件包括:

  • match4_1.dta

47
qiaqiao 发表于 2012-8-13 14:07:12
想按照年份,行业和规模配对, 按照给出的方法,即想找行业相同, 当天的规模相近的配对,
其中 'd'是日期, nindcd表示行业
bys  d nindcd sp(stkcd): g exp=_n if sp
提示错误
factor variables and time-series operators not allowed
不知道怎么解决

48
doudou1999 发表于 2012-10-20 21:05:57
学习了,感谢

49
ㄣ伪妳ぁ飞 发表于 2013-4-15 00:52:54
sungmoo 发表于 2012-4-13 09:00
use match4.dta, clear
bys year ind sp (stkcd):g exp=_n if sp
bys year ind :egen s=max(exp)
你好!我是stata菜鸟啊!我在运行这个程序的时候,在运行
forv i=1/`m'{
loc v=stkcd[`i']
replace q=. if stkcd==`v'&_n>`i'&!sp
}
时,stata会出现invalid syntax,这是因为什么啊?
期望您尽快回复,比较急~~谢谢啦!

50
ㄣ伪妳ぁ飞 发表于 2013-4-15 01:24:35
sungmoo 发表于 2012-4-13 09:00
use match4.dta, clear
bys year ind sp (stkcd):g exp=_n if sp
bys year ind :egen s=max(exp)
match5.rar (30.19 KB) 本附件包括:
  • match5.dta

谢谢sungmoo!
数据为附件match5.dta,有2年的数据,要求为试验组(即sp=1的样本,共870个)在对照组(sp=0,共2281个)中寻找配对样本,配对规则如下:
(1)同年度year。
(2)同行业ind。
(3)asset最接近,即对照组与试验组asset的差的绝对值最小。
(4)每个对照组观测值只能配对一次,尽量sp=1的每一条观测都能配对上

根据您的程序,我运行的时候循环总会出现 “valid syntax” ,这是什么原因?
希望您给个do文件,谢谢!~~~`

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

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2025-12-26 13:14