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
Create another observation type as an average of other observationsHi All, I am having trouble creating another observation under one variable which will be an averag…
Counting every pair combination on a datasetDear Statalist, Suppose you have the following dataset: City_1 City_2 Flow Pair_ID AAA BBB 456…
Matwrite installed but unrecognized commandHi, I'm having a hard time to get matwrite to work (SSC) and from here: https://ideas.repec.org/c/b…
foreach with if conditionHi, I would like to impose a condition in the foreach function on a variable which is not one of the…
Defining Program Stata HelpHi 2 Questions - 1) I was wondering if anyone had advice on how to learn to define programs in Sta…
Subscribe to:
Post Comments (Atom)
0 Response to Problem with using margins code and creating a dummy variable on command box
Post a Comment