[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
"Nick Cox" <[email protected]> |

To |
<[email protected]> |

Subject |
st: RE: by and missing values question |

Date |
Mon, 11 May 2009 13:13:38 +0100 |

Independently of the issues you raised, note that a bug lurks in this program. Your use of `1' and `2' commits you implicitly to specifying your varlist as two separate variable names, say logdiff foo bar If you, or a user of your program, specified logdiff a? because you had two variables -a1- and -a2-, say, then the program would fail, as `1' would be a? and `2' would be empty. You are relying on `1' and `2' being born as the first and second tokens typed after the command name. A safer programming practice would be to introduce an extra line tokenize "`varlist'" after the -syntax- statement, so that the program would still work either way. Finally, a further style comment. You introduce a local macro in the lines below, but it's not necessary. loc diff = r(mean) di as text "Log Difference: " as result `diff' return scalar diff = `diff' This could be condensed to di as text "Log Difference: " as result r(mean) return scalar diff = r(mean) Nick [email protected] Nikolaos Kanellopoulos I have written the following very simple program cap pr drop logdiff program define logdiff , rclass byable(recall) syntax varlist(min=2 max=2) [if] [in] [fweight aweight] version 8.0 tempvar dif marksample touse qui count local N = r(N) qui count if `touse' if r(N) == 0 error 2000 local n = r(N) qui gen `dif' = (`n'/`N')*abs(ln(`2') - ln(`1')) if `touse' qui su `dif' if `touse' [`weight'`exp'] , meanonly loc diff = r(mean) di as text "Log Difference: " as result `diff' return scalar diff = `diff' return local N = `N' return local n = `n' end My questions are: [1] How can I return the results for all categories when I use the by option and not only for the last category? [2] How can I display and return the results for the total of a category when I use the by option? i.e. return the same results as without the by option. [3] How can I exclude the missing values from my estimations both when I use and not use the by option? Thanks in advance Nikos ___________________________________________________________ Χρησιμοποιείτε Yahoo!; Βαρεθήκατε τα ενοχλητικά μηνύματα (spam); Το Yahoo! Mail διαθέτει την καλύτερη δυνατή προστασία κατά των ενοχλητικών μηνυμάτων http://login.yahoo.com/config/mail?.intl=gr * * 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/ * * 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: by and missing values question***From:*Nikolaos Kanellopoulos <[email protected]>

- Prev by Date:
**st: stcurve after stcox, strata** - Next by Date:
**RE: st: RE: Missing standard errors in multinomial logit** - Previous by thread:
**Re: st: RE: RE: by and missing values question** - Next by thread:
**st: stcurve after stcox, strata** - Index(es):

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