Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.

# st: Adjusted median and standard error using quantile regression

 From Pham Ngoc Minh To statalist@hsphsun2.harvard.edu Subject st: Adjusted median and standard error using quantile regression Date Tue, 26 Feb 2013 23:52:22 +0900

```Dear Stata users,

I have recently posted my queries about using quantile regression, and
this time I further clarified the problem.

I wish to calculate age- and sex-adjusted median and its SE of
numerical variable (respvar) according to categorical
variable(expvar), and tried running two sets of commands as follows:

set seed 1001
Prog 1:
xi: bsqreg respvar age sex i.expvar, reps(1000)
adjust age sex, by(expvar) se  f(%9.1f)
Results:
----------------------------------
expvar |         xb        stdp
----------+-----------------------
0 |       54.0       (1.5)
1 |       60.0       (1.7)
2 |       61.9       (3.5)
----------------------------------
Key:  xb    =  Linear Prediction
stdp  =  Standard Error

Prog 2:
xi: bsqreg respvar age sex i.expvar,reps(1000)
predictnl xb= xb(#1), se(stdp)
tabstat  xb stdp, by(expvar) f(%9.1f)

Results:
expvar |        xb      stdp
---------+--------------------
0 |      54.2       2.2
1 |      59.9       2.2
2 |      61.8       4.0
---------+--------------------
Total |      57.3       2.5
------------------------------

I'm not sure if the above commands are correct. I'd appreciate your suggestion.

Thank you

Ngoc Minh Pham

Thai Nguyen University College of Medicine and Pharmacy,
Faculty of Public Health, Vietnam.

On Sun, Feb 24, 2013 at 11:30 AM, Pham Ngoc Minh <phamngocm@gmail.com> wrote:
> Dear Statalists,
>
> I wish to obtain median values of depvar (redmeat) by indepvar
> (bevcat) coded 1, 2, 3 with adjustment for age and sex, and
> corresponding standard errors. I also mean to have P for trend, and
> wrote the following codes:
>
> Approach 1:
> xi: bsqreg redmeat age sex i.bevcat, reps(1000)
> adjust age sex, by(bevcat) se
> bsqreg redmeat age sex bevcat // P for trend
>
> Approach 2:
> xi: bsqreg redmeat age sex i.bevcat, reps(1000)
> predictnl yhat = xb(#1), se(sevar)
> tabstat yhat sevar, by(bevcat) stats(median)
>
> Conceivably, adjusted medians and SEs are different between the two
> methods. I'm not sure about either approach 1 or 2 is correct. I'd
> appreciate your suggesting better methods. By the way, regarding
> approach 2, command {predict} doesn't work with 'stdp' option after
> running quantile regression (Why?). Thank you for your help in
>
> Ngoc Minh Pham
>
> Thai Nguyen University College of Medicine and Pharmacy, Faculty of
> Public Health, Vietnam.
>
>
>
>
>
> On Sat, Feb 23, 2013 at 3:59 AM, Marcelo Lafleur <lafleurm@un.org> wrote:
>> Dear listmembers,
>>
>> I'm attempting to estimate elasticities using a logit model:
>>
>> . logit neting1 gastpc atenpre##saneamiento
>> . margins, eyex(*) atmeans
>>
>>         ERROR: "factor variables not allowed in option eyex()"
>>
>> However, using dydx, there is no problem:
>> . margins, dydx(*) atmeans
>>
>> To get around this problem, I have created the categorical variables of
>> interaction using either the command -xi- or  -tabulate ,generate()-.Then
>> I run the same -logit- using the categorical variables created:
>>
>> . xi i.atenpre|saneamiento, prefix(_S)
>>
>> . logit neting1 gastpc atenpre saneamiento  _SateXsanea_1
>> . margins, eyex(*) atmeans
>>
>>         This produces the output.
>>
>> I'm not 100% sure if this is a statistical/mathematical issue, or just a
>> limitation of the margins command using factor variables. Needless to say,
>> this is annoying as it requires preprocessing many variables in my model
>> to create the proper categorical variables, which could easily be done
>> with factor variables. I spent an entire afternoon trying to figure out
>> what -xi- is actually outputting and how to make it equivalent to the
>> var1##var2 option (as opposed to the var1#var2 option).
>>
>> Hope someone can shed light on this issue.
>>
>> Stata version:
>> Stata/SE 12.1 for Windows (32-bit)
>> Revision 30 Jan 2013
>> *
>> *   For searches and help try:
>> *   http://www.stata.com/help.cgi?search
>> *   http://www.stata.com/support/faqs/resources/statalist-faq/
>> *   http://www.ats.ucla.edu/stat/stata/
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/
```