Here are two ways to do this. In the first example, the variable x was created in error, and needs to be fixed:
In the second example, we would like to subtract one from each value of x:. generate x = y + 2 . generate x = y + z x already defined r(110); . drop x . generate x = y + z
replace is the same as dropping a variable and then generating its replacement.. generate x = x - 1 x already defined r(110); . replace x = x - 1 (6 real changes made)
If you already have created a Stata data set (suppose you have called it mydata), then Stata won't let you accidentally save anything else with the same name --- including a revised version of the same data set. To do this, you have to let Stata know that your request was no accident. The following example illustrates the problem and the solution.
. save mydata file mydata.dta already exists r(602); . save mydata, replace file mydata.dta saved
Suppose that y and n contain the number of "successes" and the total number of trials, respectively, and that x contains the value of a (possible) predictor.
fits the linear logistic model logit(pi) = a + bx, where pi=P(Y==1). To fit the same model, but without the term involving x, which implies that y and x are independent, use the command. blogit y n x
.blogit y n
The linear logistic model is an additive model for the log-odds (or the logit of the probability):
logit(pi) = a +bxBy contrast, the linear probability model is an additive model for the probabilities themselves:
pi = a +bxIf the number of successes, the number of trials, and the predictor variable are denoted respectively by y, n, and x, the two models above are fit, respectively, using the Stata commands
logistic regression: . blogit y n x linear probability: . generate pihat = y / n . regress pihat x
Thanks for your note.
(a) If you have already successfully copied the files, but the loglin commands don't seem to be active, skip this part and proceed to part (b).
Use a Web browser to copy the files to your Unix account.
Here are the steps using Netscape:
1. login to mach 2. start Netscape 3. visit http://www.stat.uchicago.edu/~thisted/courses/226 4. put your mouse on the link named "loglin.hlp", then hold the mouse button down until a menu pops up. Select the option to "Save this link as..." 5. save the link as "loglin.hlp" (all lower case letters). 6. repeat with the link "loglin.ado"
1. login to mach 2. give the command lynx http://www.stat.uchicago.edu/~thisted/courses/226 3. use the TAB key until the link named "loglin.hlp" is highlighted 4. type the lower-case letter "d" 5. the program will then give you one or more downloading options. Typically, the only option is "Save to Disk", which would be highlighted. 6. press the return key to save the contents of the link to your Unix disk space. 7. You will then be asked to "Enter a filename:". The program will actually suggest "loglin.hlp", so you can simply hit the return key to select that filename. 8. Repeat with the loglin.ado link. 9. Type "Q" to exit from lynx.(b) If you successfully copied the files, but the loglin commands don't seem to be active:
The original names for the files were LOGLIN.ADO and LOGLIN.HLP; unfortunately, Stata looks for files with names all in lower case (loglin.ado and loglin.hlp) in Unix versions of Stata.
If the files are in your Unix directory, the commands
mv LOGLIN.ADO loglin.ado mv LOGLIN.HLP loglin.hlpwill fix the situation.
Why, you might ask, can't loglin handle more than four variables? The reason is not very appealing: variable names in Stata are limited to eight characters in length. A five-way interaction would create variables of the form ABCDE22232 (which is obviously too long).
Fortunately, something (easy) can be done to circumvent the problem. First, create a new variable that incorporates two of your underlying variables. In Agresti's Table 7.17 on page 255, for instance, you could combine the four levels of sex and IQ. Assuming that sex and IQ are each coded using 0 and 1:
generate sexiq = 2*sex + IQYou can then run loglin with sexiq as one of the variables in loglin. If sexiq is the last variable on the list (so that loglin assigns it "D"), you should think of every term with D in it as really containin DE (that is, sex and IQ and their interaction).
At a later stage in the analysis, when things are a bit simpler, sex and IQ can be split apart, or can be combined simply with the dummy variables for the other interactions already generated by loglin.
Send candidate questions to Mr Answer Man.