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

From |
Nick Cox <n.j.cox@stata.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: RE: Re: label (automatically) |

Date |
Thu, 25 Sep 2008 16:38:01 -0500 |

That's a good case. I'll work it up for SSC in due course. Thanks, Nick Feiveson, Alan H. (JSC-SK311) wrote:

1. -defv- may let you (re)generate a variable, but putting the

definition in notes is a nuisance:

2. -defv- seems to require spaces

By contrast -labgen- puts the definition directly in the variable label

and doesn't require spaces - however -labgen won't allow regeneration.

Al F.

. drop temp*

. defv temp1 = log(day)

. defv temp2=log(day)

r(7);

. labgen temp3=log(day)

. des temp*

storage display value

variable name type format label variable label

------------------------------------------------------------------------

---------------------------

temp1 float %9.0g * temp3 float %9.0g log(day)

. notes temp1

temp1:

1. generate temp1 = log(day)

-----Original Message-----

From: owner-statalist@hsphsun2.harvard.edu

[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox

I'd forgotten about this. Thanks for the plug.

I think this predates SSC. Either way, it is probably not on SSC because

I just posted it there and did not bother to write a help file. Stuff

like that never makes the grade to SSC and thus to -njc_stuff- on SSC.

Twelve years on, that's still my inclination.

A very good reason for that, as already pointed out, is that -defv-

already exists to do the job.

A key detail for Kit's program is that -gettoken- should parse on equals

signs as well.

Also, what happens if people write -mygen double lprice = log(price)-?

Nick

n.j.cox@durham.ac.uk

Feiveson, Alan H. (JSC-SK311) wrote:

Yes - Nick Cox wrote -labgen.ado- which does excactly that. FOr some reason this is not on SSC. Perhaps Nick could make it avaliable.

*! version 1.0.1 7/17/1996

program define labgen

version 4.0

parse "`*'", parse(" =")

if "`2'"=="=" {

local var `1'

mac shift 2

}

else if "`3'"=="=" {

local type `1'

mac shift

local var `1'

mac shift 2

}

else { error 198 }

gen `type' `var' = `*'

label var `var' "`*'"

end

ChristopherNot to my knowledge. Probably the best way of documenting this is to use variable -notes-.Try this:

program mygen

qui gen `0'

gettoken name rest: 0

note `name': `0'

end

mygen lprice = log(price)

mygen gpm = 1/mpg

notes

Kit Baum, Boston College Economics and DIW Berlin http://ideas.repec.org/e/pba1.html

An Introduction to Modern Econometrics Using Stata:

http://www.stata-press.com/books/imeus.html

On Sep 25, 2008, at 1:47 PM, Alessandro Oliveira wrote:

I wonder if you could help me with an Stata issue.Is it possible for stata to automatically label a new variable with the formula used in "gen"? ex: gen y = x+1 automatically yielding label variable y with "gen y = x+1"

* * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**References**:**st: Re: label***From:*Christopher Baum <baum@bc.edu>

**st: RE: Re: label (automatically)***From:*"Feiveson, Alan H. (JSC-SK311)" <alan.h.feiveson@nasa.gov>

**Re: st: RE: Re: label (automatically)***From:*Nick Cox <n.j.cox@stata.com>

**RE: st: RE: Re: label (automatically)***From:*"Feiveson, Alan H. (JSC-SK311)" <alan.h.feiveson@nasa.gov>

- Prev by Date:
**st: Regexr Stata** - Next by Date:
**st: Netcourse Anoucement** - Previous by thread:
**st: RE: Regexr Stata** - Next by thread:
**st: St: Inequality measures** - Index(es):

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