j***m 发帖数: 74 | 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. | h****i 发帖数: 1674 | 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 | a**n 发帖数: 3801 | 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.
| j***m 发帖数: 74 | 4 Thanks all. I will try tomorrow. | j***m 发帖数: 74 | 5 The xi command workd great. Thanks a lot
【在 a**n 的大作中提到】 : http://www.stata.com/help.cgi?xi : xi i.d1*p : : p. : variable,
| j***m 发帖数: 74 | 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 | g****s 发帖数: 39 | 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
|
|