Hi everyone,
I would like to run a logistic regression of a certain variable distance to get the probability of a certain outcome valid, but instead of rows in the format
I have counts, for ex
I reasoned it should be possible to run the logistic regression with the data as it is, using frequency weights. I generated a new variable valid_ratio with
but when running the regression I get the following error:
Which I assume means Stata is interpreting all my ratios as positive outcomes.
My first question is: is it possible to run this logistic regression with the data as it is? If so, how?
If not, what is the best way to process the data to make this regression possible? The two options that come to my mind are:
Thanks in advance.
I would like to run a logistic regression of a certain variable distance to get the probability of a certain outcome valid, but instead of rows in the format
distance | valid |
500 | 1 |
500 | 1 |
500 | 0 |
1000 | 1 |
1000 | 0 |
distance | valid_count | total_count |
500 | 2 | 3 |
1000 | 1 | 2 |
Code:
. gen valid_ratio = valid_count/total_count
Code:
. logistic valid_ratio distance [fweight = total_count] outcome does not vary; remember: 0 = negative outcome, all other nonmissing values = positive outcome
My first question is: is it possible to run this logistic regression with the data as it is? If so, how?
If not, what is the best way to process the data to make this regression possible? The two options that come to my mind are:
- generate, for every currently existing observation, two rows: one with valid=1 and count=valid_count, and the other with valid=0 and count=total_count-valid_count, and then run the regression with
Code:
. logistic valid distance [fweight = count]
distance valid count 500 1 2 500 0 1 1000 1 1 1000 0 1 - generate, for each currently existing observation, total_count rows, being valid_count of them with valid=1 and total_count-valid_count of the with valid=0. In this case, the variables would be exactly in the format of the first table and I would run the regression without any weights:
Code:
. logistic valid distance
Thanks in advance.
Comment