Statalist The Stata Listserver


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

st: RE: Like %GL(r,n) in GLIM


From   "Newson, Roger B" <r.newson@imperial.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Like %GL(r,n) in GLIM
Date   Tue, 27 Feb 2007 18:11:52 -0000

I think what you are looking for is a combination of the system variable
_n (order of observation in a dataset) and the -mod()-, -int()-,
-floor()- and -ceil()- functions. For on-line help for functions in
Stata, type in Stata

whelp functions

Your first example can be created, as the variable -fact1-, by typing

gene fact1=mod(_n,4)+1

and your second example can be created, as the variable -fact2-, by
typing

gene fact2=int((_n-1)/4)

I hope this helps.

Best wishes

Roger


Roger Newson
Lecturer in Medical Statistics
Respiratory Epidemiology and Public Health Group
National Heart and Lung Institute
Imperial College London
Royal Brompton campus
Room 33, Emmanuel Kaye Building
1B Manresa Road
London SW3 6LR
UNITED KINGDOM
Tel: +44 (0)20 7352 8121 ext 3381
Fax: +44 (0)20 7351 8322
Email: r.newson@imperial.ac.uk 
www.imperial.ac.uk/nhli/r.newson/

Opinions expressed are those of the author, not of the institution.

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Herb Smith
Sent: 27 February 2007 18:03
To: statalist@hsphsun2.harvard.edu
Subject: st: Like %GL(r,n) in GLIM

Sorry for the "insider" nature of this post....  But if there are any of
you out there who remember running log-linear models under the GLIM
program, you will remember a nifty function for creating "factors" for
contingency tables.  The command

CALC newfac = %GL(r,n)

would create a variable (if I recall correctly) of 1,...,r in blocks of
n

This meant that to input a high-dimensional (or any dimensional)
contingency table, one needed to only input the counts.  The structure
of
the table (R x C, or R x C x G, etc.) could be accomplished quickly by
the
%GL command.

So, in brief, I am looking for a command that creates a variable like:

1
2
3
4
1
2
3
4

and another like

1
1
1
1
2
2
2
2

and so on.

If no %GL like command exists, fine; I'm sure I can figure out a short
way
to program this; but if such a command does exist, it would be good to
know.

Thanks,

--Herb

Professor of Sociology and
Director, Population Studies Center
230 McNeil Building
3718 Locust Walk CR
University of Pennsylvania
Philadelphia, PA  19104-6298

hsmith@pop.upenn.edu

215.898.7768 (office)
215.898.2124 (fax)
*
*   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