Dear statalist
I have a problem using margins on stata command.
I'm doing some research related to the effect of election on corporate investment.
I generated control variables called victory (which is defined as the numbers of vote that the winner got from the election. code: gen victory= max(voteparty1, voteparty2)) and difofvote (vote difference between the winner and the runner-up. For exmaple, if voteparty1> voteparty2, then the difofvote would be voteparty1-voteparty2)
Then I got two variables, 1. difofvote 2. victory.
I want to use the vote difference (difofvote ) between two major political parties to see if it is below the 25th percentile of victory margin distribution. But I'm not pretty sure what is margin distribution. I got this idea from previous studies.
Then I want to generate a dummy variable "Close" sets to one if difovote is below the 25th percentile of victory margin distribution (victorymargin). I'm new to use margins, so I'm not sure.
I found that I needed to conduct a regression before I could use the "margins" code, so I done a simple regression as follow:
reg difofvote victory, allbaselevels
After that, I wrote a code as follow:
margins, dydx(victory) at((p25) victory)
After I ran it on Stata, I found that I'm still not sure how to use this to create "Close" dummy.
So I asked my professor for help and he sent me codes as follow:
egen victorymargin_25=pctile(victorymargin), p(25)
gen Close=1 if victorymargin<=victorymargin_25 & victorymargin!=.
replace Close=0 if victorymargin>victorymargin_25 & victorymargin!=.
But they are not working and I don't think these codes are doing what I wanted to do.
So I think maybe I need to ask for some advice.
Can anyone here help me please.
Thank you!
Related Posts with Problem with using margins code and creating a dummy variable on command box
How do I loop through parts of the observations and impute missing valuesDear Statalist, My data looks like this id hypertension visit 1 . 1 1 0 2 2 . 1 2 . 2 2 1 3 3 . 1 …
Very different Results for Marginal effects vs. average marginal effects (continuous interaction)Dear all, this is my first time posting on StataList so I hope Im not in breach of most rules and r…
How to make time series on categorical variable?Hello, I want to make a line showing the development in regional scores on an index at given years.…
Interpreting interaction term in random effects modelHello! I am investigating whether implementing GSCMP (green practices) and EMS (environmental manag…
Display full value label in resultsHi all, Is there a way to stop Stata from truncating variable value labels in results tables (say i…
Subscribe to:
Post Comments (Atom)
0 Response to Problem with using margins code and creating a dummy variable on command box
Post a Comment