Stata plotting histograms next to each other - histogram

I want to plot a histogram showing how many judges graduated from each law school, by judge's birth cohort.
I am using:
twoway (histogram j_lawschool_num if j_cohort_num == 1 | j_cohort_num == 2, color(red%30)) ///
(histogram j_lawschool_num if j_cohort_num == 3 | j_cohort_num == 4, color(green%30)), ///
legend(order(1 "Judges Born Before 1959" 2 "Judges After 1959" )) xlabel(1/6,valuelabel alternate) ///
xtitle(Law School Category) ytitle(Density) graphregion(color(white) margin(large)) bgcolor(white)
But the bars are on top of each other. How can I make them next to each other so there is no overlap of bars in the same law school category?
Currently it looks like:

Related

What are the UI colors for the YouTube superchat tiers?

I'm currently doing some work with the Youtube Live Streaming Api - more specifically the live chat messages API. Its all working fine for now but my main problem is with superchats and superstickers.
https://developers.google.com/youtube/v3/live/docs/liveChatMessages#snippet.superChatDetails.tier
I'm reffering to this bit in youtube's livechat messages documentation. It addresses that each superchat has a tier variable, and that tier correspond's to a UI color which I will need when designing my UI. The documentation says
The tier is based on the amount of money spent to purchase the message. It also determines the color used to highlight the message in the live chat UI, the maximum message length, and the amount of time that the message is pinned the ticker.
The Super Chat tiers, which also cover Super Stickers, are documented in the YouTube Help Center. (See the expandable section about Super Chat purchase details.) In that list, the tier with the lowest purchase amount is tier 1, the next lowest amount is tier 2, and so forth. The Super Chat tiers, which also cover Super Stickers, are documented in the YouTube Help Center. (See the expandable section about Super Chat purchase details.) In that list, the tier with the lowest purchase amount is tier 1, the next lowest amount is tier 2, and so forth.
So I went ahead to the the Youtube Help Center and the closest thing I can find to it supposedly describing the youtube superchat tiers is this article below:
https://support.google.com/youtube/answer/9178268?visit_id=637544258197433496-560511224&rd=1
But again, this article really doesn't document anything that would be relevant to a developer.
So here is my question exactly. Does anybody out there know where I can find the documentation or if somebody knows what the YouTube Superchat tier levels and UI colors are?
If I were stuck on something like this, I would usually just test it out myself rather than trying to find specific documentation, but that's not really possible here. Since if I were to test every single tier, it would probably cost me hundreds of dollars in test donations.
Extra question:
Can anyone also explain what's going on with the whole authorDetails.sponsor vs the member resource, apparently its deprecated but I'm not sure about the exact situation of that?
I'm also trying to access the authorDetails.sponsor variable but apparently the whole Sponsor resource got deprecated and was changed to the Member resource. But then when I visit the member resource it says you need prior approval to use the members.list method but does that also include the authorDetails.sponsor variable?
Here are the documentation links below:
https://developers.google.com/youtube/v3/docs/members
https://developers.google.com/youtube/v3/live/docs/liveChatMessages#authorDetails.isChatSponsor
https://developers.google.com/youtube/v3/live/docs/sponsors
I also noticed that Google does not provide documentation on this (even though the Super Chat API docs mention it is documented.)
I've found this chart to be a useful starting point: https://www.midiaresearch.com/storage/uploads/blog/images/2017/02/Screen-Shot-2017-02-09-at-09.50.17.png
In case that image is not available in the future, here are the values:
Amount Range
Color
Time Displayed (in Ticker)
Max Characters
$1.00 - $1.99
Blue
0s
0
$2.00 - $4.99
Light blue
0s
50
$5.00 - $9.99
Green
2m
150
$10.00 - $19.99
Yellow
5m
200
$20.00 - $49.99
Orange
10m
225
$50.00 - $99.99
Magenta
30m
250
$100.00 - $199.99
Red
1hr
270
$200.00 - $299.99
Red
2hr
290
$300.00 - $399.99
Red
3hr
310
$400.00 - $499.99
Red
4hr
330
$500.00+
Red
5hr
350
The Super Chat API docs mention:
In that list, the tier with the lowest purchase amount is tier 1, the next lowest amount is tier 2, and so forth.
It's probably safe to assume that there are 11 tiers for Super Chats.
edit: I wrote some code to calculate the colors for each amount. I verified that these colors are correct. Feel free to re-use it:
/**
* Calculate the colors for a given super chat amount.
* Returns the background color [0], the header color (darkened) [1],
* and the text color [2].
* #param {string|number} amount
* #returns {[string, string, string]}
*/
const getSuperChatColors = (amount) => {
if (typeof amount === 'string') {
amount = parseFloat(amount.replace(/[^\d.-]/g, ''))
}
if (amount >= 1 && amount <= 1.99) {
return ['#1565C0', '#1565C0', '#FFFFFF']
} else if (amount >= 2 && amount <= 4.99) {
return ['#00E5FF', '#00B8D4', '#000000']
} else if (amount >= 5 && amount <= 9.99) {
return ['#0F9D58', '#0A8043', '#000000']
} else if (amount >= 10 && amount <= 19.99) {
return ['#FFCA28', '#FFB300', '#000000']
} else if (amount >= 20 && amount <= 49.99) {
return ['#F57C00', '#E65100', '#FFFFFF']
} else if (amount >= 50 && amount <= 99.99) {
return ['#E91E63', '#C2185B', '#FFFFFF']
} else if (amount >= 100 && amount <= 199.99) {
return ['#E62117', '#D00000', '#FFFFFF']
} else if (amount >= 200 && amount <= 299.99) {
return ['#E62117', '#D00000', '#FFFFFF']
} else if (amount >= 300 && amount <= 399.99) {
return ['#E62117', '#D00000', '#FFFFFF']
} else if (amount >= 400 && amount <= 499.99) {
return ['#E62117', '#D00000', '#FFFFFF']
} else if (amount >= 500) {
return ['#E62117', '#D00000', '#FFFFFF']
} else {
console.error('Invalid amount for super chat', amount)
return ['#1565C0', '#1565C0', '#FFFFFF']
}
}
Usage:
const [bgColor, headerColor, textColor] = getSuperChatColors('$100.00')
// or
const [bgColor, headerColor, textColor] = getSuperChatColors(60)
// or
const [bgColor, headerColor, textColor] = getSuperChatColors('$1')
// or
const [bgColor, headerColor, textColor] = getSuperChatColors('20')

Why my OrderSend function returns a price higher than the candle high price?

I'm trying to write an Ea with 2 moving averages, and I want it to send an order when they cross.
Sell orders seem fine, but for Buy orders in 1-min chart, the Ask price which I use to send the order is not in the candle price range. Actually I did Print("Ask=",Ask) right before my OrderEntry function and right after OrderSend(). They are equal to some price way above the candle-[High] and previous candle-[close]
But when I try higher time frames, it get closer to the candle and in daily time frame, the Ask price for orders would be in the candle range (High-Low). Does anybody know why this is happening?
void CheckForMaTrade(){
double PreviousFast = iMA(NULL,0,FastMaPeriod,FastMaShift,FastMaMethod,FastMaAppliedTo,2);
double CurrentFast = iMA(NULL,0,FastMaPeriod,FastMaShift,FastMaMethod,FastMaAppliedTo,1);
double PreviousSlow = iMA(NULL,0,SlowMaPeriod,SlowMaShift,SlowMaMethod,SlowMaAppliedTo,2);
double CurrentSlow = iMA(NULL,0,SlowMaPeriod,SlowMaShift,SlowMaMethod,SlowMaAppliedTo,1);
if(PreviousFast<PreviousSlow && CurrentFast>CurrentSlow)
OrderEntry(0);
if(PreviousFast>PreviousSlow && CurrentFast<CurrentSlow)
OrderEntry(1);
}
void OrderEntry(int direction){
if(direction == 0){
double bsl=0;
double btp=0;
if(StopLoss != 0)
bsl = Ask-(StopLoss*pips);
if(TakeProfit != 0)
btp = Ask+(TakeProfit*pips);
if(OpenOrdersThisPair(Symbol()) < 10 )
OrderSend(NULL,OP_BUY,LotSize,Ask,0,bsl,btp,NULL,MagicNumber,0,Gold);
}
enter image description here
In MT4, the candles are drawn by BID prices only. ASK prices are not taken into consideration. So it is possible that Ask > highest bid.

How to handle weight conversions

I'm currently facing an issue converting between metrics and imperial weights when working with gym equipment. So here in the UK we work with weights in Kilo's where they can increment by 1.25, but overseas i.e. US the weights are measured in pounds and can increment by 0.5.
Handling this isn't an issue, the issue arises when I use the formula to convert between kilo, pounds and vice versa the values are way off. For example a standard UK barbell is 20KG and a US barbell is 45lbs, but when i use the Measurement class to convert it will spit out 44.0925. I already know to convert kilo to pounds you have to multiply it by 2.205 but this is just one example and other values are just as way off.
I've already thought of some other possible solutions one being having an array of possible values in kilos and another that will hold a possible values in pounds but this feels hacky and also wouldn't work since users can input their values into a textfield, which may be an invalid value.
Just curious to see/know if anyone has tackled switching between weight conversion before especially with gym equipment.
I have achieved this by keeping what user has selected option is like it is pound or kg
enum WeightUnitConverted:String {
case kg = "kg"
case pounds = "pound"
case none = ""
}
var weightUnitConvertedValue: WeightUnitConverted = WeightUnitConverted.kg
You have to change this weightUnitConvertedValue whenever the user changes the measurement type. before that you can convert the values
like this I have MVVM
self.viewModel.updateWeightUnit(string: self.weightUnit[selectedRow]) // Like kg or pound, So self.viewModel.weightUnit = "kg"
self.viewModel.updateWeight(string: self.viewModel.convertWeightValues())
self.txtWeight.text = self.viewModel.weight
self.viewModel.weightUnitConvertedValue = WeightEntryViewModel.WeightUnitConverted(rawValue: self.viewModel.weightUnit)!
Here is convertWeightValues()
func convertWeightValues() -> String {
// We need to convert to pounds
if weightUnit.lowercased() == "pound" && weightUnitConvertedValue == .kg {
let punds = convertKGtoPounds()
return punds > 0 ? punds.asNumber : ""
} else if weightUnit.lowercased() == "kg" && weightUnitConvertedValue == .pounds {
// We need to convert to KG
let kg = convertPoundsToKG()
return kg > 0 ? kg.asNumber : ""
}
return self.weight //No need to change so return current weight
}
I know this is a bit confusing for you to implement someone's code Please ask me whatever query you have

Dealing with Bubble Chart overlap

We're working on a Highcharts Bubble Chart w/category axis and a lot of overlapping data points. Is there any way to control exactly how the bubbles are placed within the category? What we'd like to do is sort the bubbles ahead of time and then offset them from each other a bit. Some overlap is desirable so we'd prefer to not have to add additional categories to make sure there is no overlap.
Unfortunately we have no solution for controling positions of the bubbles. But you can request your propositin in our uservoice system http://highcharts.uservoice.com/
If you are using categories, your x values are the array index of the category for your value.
So to tweak the placement, you can tweak your x value by adding/subtracting small decimal amounts:
http://jsfiddle.net/yPLVP/10/
[-0.1,2,10]
Keeping in mind that +/- .5 is the center point between the categories - so for a value that falls within the 3rd category (x value 2), keep your x values between 1.55 and 2.45 (or so....)
I have the same problem, you can add this code:
function(chartObj) {
$.each(chartObj.series[0].data, function(i, point) {
var aux = 0;
if (i % 2 == 0)
aux = point.dataLabel.y + 6;
else
aux = point.dataLabel.y - 6;
point.dataLabel.attr({y:aux});
});
jsFiddle: http://jsfiddle.net/9m6wu/277/

Finding the Oriented Bounding Box of a Convex Hull in XNA Using Rotating Calipers

Perhaps this is more of a math question than a programming question, but I've been trying to implement the rotating calipers algorithm in XNA.
I've deduced a convex hull from my point set using a monotone chain as detailed on wikipedia.
Now I'm trying to model my algorithm to find the OBB after the one found here:
http://www.cs.purdue.edu/research/technical_reports/1983/TR%2083-463.pdf
However, I don't understand what the DOTPR and CROSSPR methods it mentions on the final page are supposed to return.
I understand how to get the Dot Product of two points and the Cross Product of two points, but it seems these functions are supposed to return the Dot and Cross Products of two edges / line segments. My knowledge of mathematics is admittedly limited but this is my best guess as to what the algorithm is looking for
public static float PolygonCross(List<Vector2> polygon, int indexA, int indexB)
{
var segmentA1 = NextVertice(indexA, polygon) - polygon[indexA];
var segmentB1 = NextVertice(indexB, polygon) - polygon[indexB];
float crossProduct1 = CrossProduct(segmentA1, segmentB1);
return crossProduct1;
}
public static float CrossProduct(Vector2 v1, Vector2 v2)
{
return (v1.X * v2.Y - v1.Y * v2.X);
}
public static float PolygonDot(List<Vector2> polygon, int indexA, int indexB)
{
var segmentA1 = NextVertice(indexA, polygon) - polygon[indexA];
var segmentB1 = NextVertice(indexB, polygon) - polygon[indexB];
float dotProduct = Vector2.Dot(segmentA1, segmentB1);
return dotProduct;
}
However, when I use those methods as directed in this portion of my code...
while (PolygonDot(polygon, i, j) > 0)
{
j = NextIndex(j, polygon);
}
if (i == 0)
{
k = j;
}
while (PolygonCross(polygon, i, k) > 0)
{
k = NextIndex(k, polygon);
}
if (i == 0)
{
m = k;
}
while (PolygonDot(polygon, i, m) < 0)
{
m = NextIndex(m, polygon);
}
..it returns the same index for j, k when I give it a test set of points:
List<Vector2> polygon = new List<Vector2>()
{
new Vector2(0, 138),
new Vector2(1, 138),
new Vector2(150, 110),
new Vector2(199, 68),
new Vector2(204, 63),
new Vector2(131, 0),
new Vector2(129, 0),
new Vector2(115, 14),
new Vector2(0, 138),
};
Note, that I call polygon.Reverse to place these points in Counter-clockwise order as indicated in the technical document from perdue.edu. My algorithm for finding a convex-hull of a point set generates a list of points in counter-clockwise order, but does so assuming y < 0 is higher than y > 0 because when drawing to the screen 0,0 is the top left corner. Reversing the list seems sufficient. I also remove the duplicate point at the end.
After this process, the data becomes:
Vector2(115, 14)
Vector2(129, 0)
Vector2(131, 0)
Vector2(204, 63)
Vector2(199, 68)
Vector2(150, 110)
Vector2(1, 138)
Vector2(0, 138)
This test fails on the first loop when i equals 0 and j equals 3. It finds that the cross-product of the line (115,14) to (204,63) and the line (204,63) to (199,68) is 0. It then find that the dot product of the same lines is also 0, so j and k share the same index.
In contrast, when given this test set:
http://www.wolframalpha.com/input/?i=polygon+%282%2C1%29%2C%281%2C2%29%2C%281%2C3%29%2C%282%2C4%29%2C%284%2C4%29%2C%285%2C3%29%2C%283%2C1%29
My code successfully returns this OBB:
http://www.wolframalpha.com/input/?i=polygon+%282.5%2C0.5%29%2C%280.5%2C2.5%29%2C%283%2C5%29%2C%285%2C3%29
I've read over the C++ algorithm found on http://www.geometrictools.com/LibMathematics/Containment/Wm5ContMinBox2.cpp but I'm too dense to follow it completely. It also appears to be very different than the other one detailed in the paper above.
Does anyone know what step I'm skipping or see some error in my code for finding the dot product and cross product of two line segments? Has anyone successfully implemented this code before in C# and have an example?
Points and vectors as data structures are essentially the same thing; both consist of two floats (or three if you're working in three dimensions). So, when asked to take the dot product of the edges, I suppose it means taking the dot product of the vectors that the edges define. The code you provided does exactly this.
Your implementation of CrossProduct seems correct (see Wolfram MathWorld). However, in PolygonCross and PolygonDot I think you shouldn't normalize the segments. It will affect the magnitude of the return values of PolygonDot and PolygonCross. By removing the superfluous calls to Vector2.Normalize you can speed up your code and reduce the amount of noise in your floating point values. However, normalization is not relevant to the correctness of the code that you have pasted as it only compares the results with zero.
Note that the paper you refer to assumes that the polygon vertices are listed in counterclockwise order (page 5, first paragraph after "Beginning of comments") but your example polygon is defined in clockwise order. That's why PolygonCross(polygon, 0, 1) is negative and you get the same value for j and k.
I assume DOTPR is a normal vector dot product, crosspr is a crossproduct. dotproduct will return a normal number , crossproduct will return a vector which is perpendicular to the two vectors given. (basic vector math,check wikipedia)
they are actually defined in the paper as DOTPR(i,j) returns dotproduct of vectors from vertex i to i+1 and j to j+1. same for CROSSPR but with cross product.

Resources