Redian新闻
>
a question about stata code
avatar
a question about stata code# Economics - 经济
j*m
1
i have a set of dummies, say d1 d2...d9, and i have another variable, say p.
now i want to multiply each dummy by p, and generate a new set of variable,
say pd1=p*d1,pd2=p*d2,....
how can i do that in once. i know the cumbersome and stupid way is to
generate one by one, like
gen pd1=p*d1
gen pd2=p*d2
...
thanks.
avatar
h*i
2
if p1 to pn are stored in the order of 1-n in the memory, you can write
codes like these in you do file
foreach var in vallist p1-pn {
gen p`var'=p*`var'
}
you can search help file for foreach to see the details
avatar
a*n
3
http://www.stata.com/help.cgi?xi
xi i.d1*p

p.
variable,

【在 j***m 的大作中提到】
: i have a set of dummies, say d1 d2...d9, and i have another variable, say p.
: now i want to multiply each dummy by p, and generate a new set of variable,
: say pd1=p*d1,pd2=p*d2,....
: how can i do that in once. i know the cumbersome and stupid way is to
: generate one by one, like
: gen pd1=p*d1
: gen pd2=p*d2
: ...
: thanks.

avatar
j*m
4
Thanks all. I will try tomorrow.
avatar
j*m
6
new question comes.
since in my model, I have two firms, and I have one indicator for each firm,
say p1,p2. and another set of product dummies.
I know by xi I can generate p1*d(n), but since I need to generate p1*d(n)
and p2*d(n) at the same time, and if I use xi and generate p1*d(n) first and
p2*d(n) second, p2*d(n) will replace p1*d(n), and I only get p2*d(n).
Another problem is by using xi, it not only generates p*d(n), but also
generate d(n), so every time I have to drop d(n) after I generat
avatar
g*s
7
use do file
forval i=1/m {
forval j=1/n{
gen p`i'_d`j'=p`i'*d`j'
}
}

firm,
and

【在 j***m 的大作中提到】
: new question comes.
: since in my model, I have two firms, and I have one indicator for each firm,
: say p1,p2. and another set of product dummies.
: I know by xi I can generate p1*d(n), but since I need to generate p1*d(n)
: and p2*d(n) at the same time, and if I use xi and generate p1*d(n) first and
: p2*d(n) second, p2*d(n) will replace p1*d(n), and I only get p2*d(n).
: Another problem is by using xi, it not only generates p*d(n), but also
: generate d(n), so every time I have to drop d(n) after I generat

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。