Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Using one variable to label another


From   "Doogar, Rajib" <doogar@uiuc.edu>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: Using one variable to label another
Date   Mon, 20 Nov 2006 02:41:03 -0600

In Stat 9.2, how can I use the values of v2 (str 40, say) to label v1
(int)?  My data looks something like this:

V1      V2
1234    somerandomstring1
1234    somerandomstring1
2345    somerandomstring2
....
6578    somerandomstringn
....
etc.

I tried to encode v2 and then attach the resulting label to v1.  I
encoded v2 all right, but then got stumped by how correctly to link the
labels to the values of v1.  Encoding v2 gave me labels numbered 1 to
xxx, but v1 is a four digit number (although it does take exactly xxx
distinct values).

Many thanks!

Rajib Doogar,
Department of Accountancy,
The University of Illinois at Urbana-Champaign
1206 S. Sixth Street, Champaign, IL 61820
Ph: 217.244.8083, Fax: 217.244.0902
http://www.cba.uiuc.edu/doogar



-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox
Sent: Tuesday, May 30, 2006 9:54 AM
To: statalist@hsphsun2.harvard.edu
Subject: RE: st: Calculating Percent Change In Regression Coeffecients

On a different note, why this interest in percent change in coefficient
as a metric?

I make three elementary comments.

1. The behaviour of ratios can be complicated already. This measure is a
ratio calculated from ratios.

2. Specifically, is the behaviour as the denominator goes from small
positive through zero to small negative regarded as a feature?

3. There is a lack of symmetry in the calculation.

I can imagine a practical argument that (1) and
(2) do not matter for the application, and (3) might be irrelevant given
a time order, but I wouldn't put much weight on this measure.

Nick
n.j.cox@durham.ac.uk

Tim Wade

> Hi Raphael, I don't know how to do this in Mata, but here is a brute
> force solution using macros and for loops:
>
>
> . regress price headroom rep78 gear_ratio
>
>       Source |       SS       df       MS              Number
> of obs =      69
> -------------+------------------------------           F(  3,
>    65) =    4.68
>        Model |   102521828     3  34173942.7           Prob >
> F      =  0.0051
>     Residual |   474275131    65  7296540.47
> R-squared     =  0.1777
> -------------+------------------------------           Adj
> R-squared =  0.1398
>        Total |   576796959    68  8482308.22           Root
> MSE      =  2701.2
>
> --------------------------------------------------------------
> ----------------
>        price |      Coef.   Std. Err.      t    P>|t|
> [95% Conf. Interval]
> -------------+------------------------------------------------
> ----------------
>     headroom |  -136.9778   414.9107    -0.33   0.742
> -965.6117    691.6561
>        rep78 |   576.2363   362.8717     1.59   0.117
> -148.4686    1300.941
>   gear_ratio |  -2995.126   829.7523    -3.61   0.001
> -4652.256   -1337.996
>        _cons |   13577.64   3025.567     4.49   0.000
> 7535.166    19620.12
> --------------------------------------------------------------
> ----------------
>
> /*only include coefficients you want to compare*/
>
> . foreach var of varlist headroom rep78 {
>   2. local `var'1=_b[`var']
>   3. }
>
> . regress price headroom rep78
>
>       Source |       SS       df       MS              Number
> of obs =      69
> -------------+------------------------------           F(  2,
>    66) =    0.43
>        Model |  7450346.06     2  3725173.03           Prob >
> F      =  0.6511
>     Residual |   569346613    66  8626463.83
> R-squared     =  0.0129
> -------------+------------------------------           Adj
> R-squared = -0.0170
>        Total |   576796959    68  8482308.22           Root
> MSE      =  2937.1
>
> --------------------------------------------------------------
> ----------------
>        price |      Coef.   Std. Err.      t    P>|t|
> [95% Conf. Interval]
> -------------+------------------------------------------------
> ----------------
>     headroom |   391.6261   422.1074     0.93   0.357
> -451.1385    1234.391
>        rep78 |   69.23416   363.8024     0.19   0.850
> -657.1208    795.5892
>        _cons |   4735.368   1930.863     2.45   0.017
> 880.276    8590.459
> --------------------------------------------------------------
> ----------------
>
> . foreach var of varlist headroom rep78 {
>   2. local `var'2=_b[`var']
>   3. }
>
> . foreach var of varlist headroom rep78 {
>   2. di as result "percent change for
> `var'="((``var'2'-``var'1')/``var'1')*100
>   3. }
> percent change for headroom=-385.90483 percent change for
> rep78=-87.985109

Raphael Fraser

>> I would like to calculate the percentage change in the regression
>> coeffecients of model 1 and model 2. Can any one help? I tried using

>> Mata but I did not know how to divide each element in a matrix with
>> different scalars.
>>
>> sysuse auto, clear
>> stset mpg, failure(foreign)
>> stcox mpg price weight rep78, nohr nolog /*Model 1*/ stcox mpg
>> weight rep78, nohr nolog /*Model 2*/
>>
>> For example % change = (rep78_m2 - rep78_m1) / rep78_m1

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index