Hello Stata community
I run the following mlogit:
Where y take 3 values 0, 1, 2
I want to do the following 2 things:
1. Estimate the probability outcome using mean value of x1, x2, and x3 (but year and indus varies), given y take specific value 1 or 2. Then create in new column
This means firms in the same industry and same year should have same predict probability
2. Estimate the probability outcome for each x1, x2, and x3 while keeping the other two variables at mean value, given y take specific value 1 or 2. Then create in new column
For example p(x1 | y=1) = invlogit(a + b1*x1 + b2*mean(x2) + b3*mean(x3) + year + indus) given y = 1
And so on for x2 and x3
I am not quiet sure how to do this efficiency since
does not have any option (or I do not know) to explicitly choosing input value
My temporary solution so far:
Hope someone could help me
Thank you
I run the following mlogit:
Code:
mlogit(y) = a + b1*x1 + b2*x2 + b3*x3 + i.year + i.indus
I want to do the following 2 things:
1. Estimate the probability outcome using mean value of x1, x2, and x3 (but year and indus varies), given y take specific value 1 or 2. Then create in new column
This means firms in the same industry and same year should have same predict probability
2. Estimate the probability outcome for each x1, x2, and x3 while keeping the other two variables at mean value, given y take specific value 1 or 2. Then create in new column
For example p(x1 | y=1) = invlogit(a + b1*x1 + b2*mean(x2) + b3*mean(x3) + year + indus) given y = 1
And so on for x2 and x3
I am not quiet sure how to do this efficiency since
Code:
predict
My temporary solution so far:
Code:
use https://www.stata-press.com/data/r18/lbw, clear
gen y = low
gen x1 = age
gen x2 = smoke
gen x3 = ptl
foreach var of varlist x1 x2 x3 {
summarize `var', meanonly
gen m_`var' = r(mean)
gen ori_`var' = `var'
}
mlogit y x1 x2 x3
* Step 2: Loop to replace, predict, and restore
foreach var of varlist x1 x2 x3 {
* Replace x(i) with its mean
replace `var' = m_`var'
* Predict outcome probabilities with x(i) set to its mean
predict y1_p`var', pr outcome(1)
predict y2_p`var', pr outcome(2)
* Restore original values of x(i)
replace `var' = ori_`var'
}
Hope someone could help me
Thank you

Comment