Skip to content

Commit

Permalink
s
Browse files Browse the repository at this point in the history
s
  • Loading branch information
riosavila committed Aug 31, 2024
1 parent 748f5b5 commit 4e102bb
Show file tree
Hide file tree
Showing 3 changed files with 164 additions and 163 deletions.
194 changes: 89 additions & 105 deletions color_style/color_style.sthlp
Original file line number Diff line number Diff line change
Expand Up @@ -4,154 +4,135 @@
{title:Title}

{phang}
{bf:color_style} {hline 2} Module to change colors in your scheme file.
{p2colreset}{...}
{bf:color_style} {hline 2} Module to change colors in your scheme file


{title:Syntax}

{p 8 16 2}
{cmd:color_style} [palette], [graph list] [n(#) {help colorpalette} options]
{cmd:color_style} [{it:palette}] [, {it:options}]

{synoptset 12 tabbed}{...}
{marker opt}{synopthdr:options}
{synoptset 20 tabbed}{...}
{synopthdr}
{synoptline}
{syntab:Main}
{synopt:{opt g:raph}}display the palette of colors to be applied{p_end}
{synopt:{opt rand:om}}select a random palette from those available with the package{p_end}
{synopt:{opt list}}provide a list of palettes that accompany this file{p_end}
{synopt:{opt list(letter)}}provide a list of palettes that start with "letter"{p_end}
{synopt:{opt n(#)}}define the number of colors to be used for the palette (1-15){p_end}
{synopt:{opt i:polate(#)}}same as {opt n()}, but works with Stata versions earlier than 14.2{p_end}
{synopt:{opt show:case}}show how the palette will look for up to 15 colors{p_end}
{synopt:{help colorpalette##options:{it:colorpalette_options}}}any options from {helpb colorpalette}{p_end}
{synoptline}

{p2coldent : {opt palette}} Specifies a particular palette to be applied to the Scheme file. One can use
any of the palettes or color options following {help colorpalette} syntax, or the palettes provided along with this command.
See {cmd: list}.
{p 4 6 2}
{cmd:font_style} {it:font}

{synopt : {cmd: graph}} When requested, the command will display the palette of colors one will apply.
{p 4 6 2}
{cmd:graphquery} [{it:options}]

{synopt : {cmd: random}} Selects a random palette from the ones available with the package.

{synopt : {cmd: list}} Provides a list of Palettes that accompany this file. These are in addition to the ones in {help colorpalette}.
{title:Description}

{synopt : {cmd: list(letter)}} Provides a list of Palettes that start with "letter".
{pstd}
{cmd:color_style} provides an easy way to change the palette colors in your scheme and graphs.
It works as a wrapper for {helpb colorpalette} and {helpb grstyle}. The palettes were put together
by Blake Robert Mills, Karthik Ram, and Jake Lawlor.

{pstd}
Because this command works as a wrapper for {cmd:colorpalette}, you can easily use your own palettes
or the ones in {cmd:colorspace} to enhance your graphs.

{synopt :{cmd: n(#)}} Defines the number of colors to be used for the palette. n(#) should be between 1 to 15. If you select a number larger than 15, those colors will not be used in the scheme file. If n(#)<15, unused pstyle's will be recycled.
{pstd}
{cmd:font_style} changes the font face for your graphs.

{synopt :{cmd: ipolate(#)}} Same as with n(#). However, using n(#) does not work under Stata versions earlier than 14.2.
{pstd}
{cmd:graphquery} returns the scheme properties associated with a particular option.

{synopt : } The default is to use the number of colors in the palette. For exaple {cmd: Greek} has 5 default colors. Using and n(#) higher or lower than this will interpolate colors. See the options in {help colorpalette}.

{synopt :{cmd:showcase}} This will show you how the palette will look for up to 15 colors.
{title:Options}

Extra:
{phang}
{opt palette} specifies a particular palette to be applied to the scheme file. You can use
any of the palettes or color options following {help colorpalette} syntax, or the palettes provided
with this command. See {cmd:list} option.

{p 8 16 2}
{cmd:font_style} {it: font}
{phang}
{opt graph} displays the palette of colors to be applied.

This has 1 job. Change the fontface for your graphs.
{phang}
{opt random} selects a random palette from those available with the package.

{p 8 16 2}
{cmd:graphquery} {it: options}
{phang}
{opt list} provides a list of palettes that accompany this file. These are in addition to those in {help colorpalette}.

This has 1 job. Returns the scheme properties associated to a particular option.
{phang}
{opt list(letter)} provides a list of palettes that start with "letter".

For example "graphquery color p1" should provide the color assigned to color p1 (navy for s2color).
{phang}
{opt n(#)} defines the number of colors to be used for the palette. {it:#} should be between 1 and 15.
If you select a number larger than 15, those colors will not be used in the scheme file. If {it:#} < 15,
unused pstyles will be recycled.

{marker description}{...}
{title:Description}
{phang}
{opt ipolate(#)} same as {opt n(#)}. However, {opt n(#)} does not work under Stata versions earlier than 14.2.

{p}This module aims to provide an easy way to change the palette colors in your scheme and graphs.
{p_end}
{phang}
{opt showcase} shows how the palette will look for up to 15 colors.

{p}This command works as a wrapper on top of Ben Jann's {help colorpalette} and {help grstyle}. Whereas the palette's
were put together by Blake Robert Mills, Karthik Ram and Jake Lawlor.
{p_end}
{pstd}
The default is to use the number of colors in the palette. For example, {cmd:Greek} has 5 default colors.
Using an {opt n(#)} higher or lower than this will interpolate colors. See the options in {help colorpalette}.

{p}Because this command works as a wrapper for colorpalette, you can easily use your own palettes, or the ones in colorspace to make your graphs shine.

{marker examples}{...}
{title:Examples}

{pstd}Lets start by loading some data:{p_end}

{phang2}
{bf:. {stata "use http://fmwww.bc.edu/RePEc/bocode/o/oaxaca.dta"}}{p_end}
{phang2}
{bf:. {stata "set scheme white"}}{p_end}

Say that you are considering using one of the color palettes that comes with this command.
However, you do not know what is available, so you start by simply typing:{p_end}

{phang2}
{bf:. {stata "color_style , list"}}
{pstd}Load some data:{p_end}
{phang2}{cmd:. use http://fmwww.bc.edu/RePEc/bocode/o/oaxaca.dta}{p_end}
{phang2}{cmd:. set scheme white}{p_end}

{pstd}
Now, assume you want decide for the enigmatic Egypt, but are unsure about the colors,
then you can type:{p_end}

{phang2}
{bf:. {stata "color_style egypt, graph"}}

{pstd}
What you will see is that this palette uses 4 colors. So only the first 4 Styles would be modified.
You could extend this palette to 15 colors: {p_end}
{pstd}List available palettes:{p_end}
{phang2}{cmd:. color_style, list}{p_end}

{phang2}
{bf:. {stata "color_style egypt, graph n(15)"}}
{pstd}Display the Egypt palette:{p_end}
{phang2}{cmd:. color_style egypt, graph}{p_end}

{pstd}
You may or may not like this set of colors interpolated. Alternatively, you can choose to recycle the colors,
using option {cmd:class()}. This is a colorpalette option: {p_end}
{pstd}Extend the Egypt palette to 15 colors:{p_end}
{phang2}{cmd:. color_style egypt, graph n(15)}{p_end}

{phang2}
{bf:. {stata "color_style egypt, graph n(15) class(q)"}}
{pstd}Recycle colors using the {cmd:class()} option:{p_end}
{phang2}{cmd:. color_style egypt, graph n(15) class(q)}{p_end}

{pstd}
So, lets settle with the option above, and now make a simple scatter plot {p_end}
{pstd}Create a scatter plot with the selected palette:{p_end}
{phang2}{cmd:. xtile q4 = exper, n(4)}{p_end}
{phang2}{cmd:. separate lnwage, by(q4)}{p_end}
{phang2}{cmd:. scatter lnwage? exper}{p_end}

{phang2}
{bf:. {stata "xtile q4=exper, n(4)"}}{p_end}
{phang2}
{bf:. {stata "separate lnwage,by(q4)"}}{p_end}
{phang2}
{bf:. {stata "scatter lnwage? exper"}}
{pstd}Try different palettes:{p_end}
{phang2}{cmd:. color_style peru1}{p_end}
{phang2}{cmd:. scatter lnwage? exper}{p_end}
{phang2}{cmd:. color_style peru2}{p_end}
{phang2}{cmd:. scatter lnwage? exper}{p_end}
{phang2}{cmd:. color_style johnson}{p_end}
{phang2}{cmd:. scatter lnwage? exper}{p_end}
{phang2}{cmd:. graph bar lnwage?, stack}{p_end}
{phang2}{cmd:. color_style viridis, n(5)}{p_end}
{phang2}{cmd:. scatter lnwage? exper}{p_end}
{phang2}{cmd:. graph bar lnwage?, stack}{p_end}

{pstd}
But of course, we can change this with any other palette:{p_end}

{phang2}
{bf:. {stata "color_style peru1"}}{p_end}
{phang2}
{bf:. {stata "scatter lnwage? exper"}}{p_end}
{phang2}
{bf:. {stata "color_style peru2"}}{p_end}
{phang2}
{bf:. {stata "scatter lnwage? exper"}}{p_end}
{phang2}
{bf:. {stata "color_style johnson"}}{p_end}
{phang2}
{bf:. {stata "scatter lnwage? exper"}}{p_end}
{phang2}
{bf:. {stata "graph bar lnwage?, stack"}}{p_end}
{phang2}
{bf:. {stata "color_style viridis, n(5)"}}{p_end}
{phang2}
{bf:. {stata "scatter lnwage? exper"}}{p_end}
{phang2}
{bf:. {stata "graph bar lnwage?, stack"}}

{title:Acknowledgements}

{pstd}
Finally, if you are interested looking at how many of the palettes look with , scatterplots, violinplots,
or stream plots, you can look here: {browse "https://github.com/friosavila/playingwithstata/blob/gh-pages/articles/palette.md"}

{marker Aknowledgement}{...}
{title:Aknowledgement}
This command would not have been possible without the work of Ben Jann, who made it possible to easily
manipulate colors in Stata using {cmd:colorpalette}, as well as his work with {cmd:grstyle}, which makes
it quite easy to manipulate schemes.

{pstd}
This command could not have been possible without the work by Ben Jann, who make it possible to easily manipulate colors in Stata using colorpalette, as well as his work with grstyle, which make it quite easy to manipulate schemes.
{p_end}
Furthermore, thanks to Blake Robert Mills, Karthik Ram, and Jake Lawlor, who put together amazing palettes.

{pstd}
Furthermore, thank you to Blake Robert Mills, Karthik Ram and Jake Lawlor, who put together very amazing palettes.
{p_end}

{marker Author}{...}
{title:Author}

{pstd}Fernando Rios-Avila{break}
Expand All @@ -160,8 +141,11 @@ Blithewood-Bard College{break}
Annandale-on-Hudson, NY{break}
[email protected]


{title:Also see}

{p 7 14 2}
{p 4 14 2}
Help: {helpb colorpalette}, {helpb grstyle}

{p 7 14 2}
Online: {browse "https://github.com/friosavila/playingwithstata/blob/gh-pages/articles/palette.md":Palette examples}
92 changes: 54 additions & 38 deletions cre/cre.sthlp
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{smcl}
{* *! version 1 7july22}{...}
{* *! version 1.1 30Aug24}{...}
{findalias asfradohelp}{...}
{vieweralsosee "" "--"}{...}
{viewerjumpto "Syntax" "examplehelpfile##syntax"}{...}
{viewerjumpto "Description" "examplehelpfile##description"}{...}
{viewerjumpto "Options" "examplehelpfile##options"}{...}
{viewerjumpto "Remarks" "examplehelpfile##remarks"}{...}
{viewerjumpto "Examples" "examplehelpfile##examples"}{...}
{viewerjumpto "Syntax" "cre##syntax"}{...}
{viewerjumpto "Description" "cre##description"}{...}
{viewerjumpto "Options" "cre##options"}{...}
{viewerjumpto "Remarks" "cre##remarks"}{...}
{viewerjumpto "Examples" "cre##examples"}{...}
{title:Title}

{phang}
{bf:cre} {hline 2} Prefix program used for the estimation of Correlated Random Effect models
{bf:cre} {hline 2} Prefix program for estimating Correlated Random Effect models


{marker syntax}{...}
Expand All @@ -23,72 +23,88 @@
{synopthdr}
{synoptline}
{syntab:Main}
{synopt:{opt abs(varlist)}}Provides the list of "fixed effects" that will be used to to create independent variable "means" {p_end}
{synopt:{opt keep}}request to "keep" the created variables after the estimation command is excecuted{p_end}
{synopt:{opt compact }}Request to create a single "mean" variable that aggregates all fixed effects means. The default is to create a separate variable per fixed effect{p_end}
{synopt:{opt keepsingletons}}Request "keeping" singletons, when estimating the indep. variable means. Default option is to drop singletons{p_end}
{synopt:{opth prefix(name)}}provides a string to be used as prefix for the newly created variables. THe default is using "m", so that the new variable will be named "m#_varname" or "m_varname" {p_end}
{synopt:{opt abs(varlist)}}specifies the "fixed effects" variables used to create independent variable "means"{p_end}
{synopt:{opt keep}}retains the created variables after the estimation command is executed{p_end}
{synopt:{opt compact}}creates a single "mean" variable aggregating all fixed effects means (default is to create a separate variable per fixed effect){p_end}
{synopt:{opt keepsingletons}}retains singletons when estimating the independent variable means (default is to drop singletons){p_end}
{synopt:{opth prefix(name)}}specifies a string to be used as prefix for newly created variables (default is "m", resulting in "m#_varname" or "m_varname"){p_end}
{synoptline}

{marker description}{...}
{title:Description}

{pstd}
{cmd:cre} is a prefix command that allows the user to easily implement correlated random effect models given a set of "fixed effects".
{cmd:cre} is a prefix command that facilitates the implementation of correlated random effect models given a set of "fixed effects".

{pstd}For example, consider a simple panel model:
{pstd}Consider a simple panel model:

{pstd} y_it = a_i + b * x_it + e_it

{pstd}The standard approach is to absorb (partial out) fixed effects, and estimate model coefficients on the the residual data:
{pstd}The standard approach is to absorb (partial out) fixed effects and estimate model coefficients on the residual data:

{pstd} y_it -E[y_it|i] = b * (x_it-E[x_it|i]) + e_it
{pstd} y_it - E[y_it|i] = b * (x_it - E[x_it|i]) + e_it

{pstd}The CRE model, instead aims to estimate the following model:
{pstd}The CRE model instead aims to estimate the following:

{pstd} y_it = b0 + b * x_it + b_m * (E[x_it|i]-E[x_it]) + e_it
{pstd} y_it = b0 + b * x_it + b_m * (E[x_it|i] - E[x_it]) + e_it

{pstd}For the linear model, this approach provides numerically identical results for the point estimates of "b".
{pstd}For linear models, this approach provides numerically identical results for the point estimates of "b".
The advantage, however, comes from using this strategy for nonlinear models.

{pstd}Keep in mind that this command simply creates the new variables and adds them to the model specification. It does not account for standard error or degrees of freedom corrections.
{pstd}Note that this command only creates new variables and adds them to the model specification. It does not account for standard error or degrees of freedom corrections.

{marker options}{...}
{title:Options}

{dlgtab:Main}

{phang}
{opt abs(varlist)} specifies the "fixed effects" variables used to create independent variable "means".

{phang}
{opt keep} retains the created variables after the estimation command is executed.

{phang}
{opt compact} creates a single "mean" variable aggregating all fixed effects means. The default is to create a separate variable per fixed effect.

{phang}
{opt keepsingletons} retains singletons when estimating the independent variable means. The default is to drop singletons.

{phang}
{opth prefix(name)} specifies a string to be used as prefix for newly created variables. The default is "m", resulting in "m#_varname" or "m_varname".

{marker remarks}{...}
{title:Remarks}

{pstd}
This program was created simply as a tool to facilitate the comparison of CRE in quantile regression setups.
This program was created as a tool to facilitate the comparison of CRE in quantile regression setups.

{pstd}It uses Sergio Correira {help reghdfe}
{pstd}It uses Sergio Correia's {help reghdfe} command.

{pstd}All errors are my own.
{pstd}All errors are the author's own.

{marker examples}{...}
{title:Examples}

{phang}{stata "sysuse auto"}{p_end}
{phang}{stata "replace headroom=round(headroom)"}{p_end}
{phang}{stata "replace price=price/1000"}{p_end}
{phang}{stata "replace headroom = round(headroom)"}{p_end}
{phang}{stata "replace price = price / 1000"}{p_end}

{phang}{stata "regress mpg price foreign i.headroom"}{p_end}
{phang}{stata "reghdfe mpg price foreign, abs(headroom)"}{p_end}
{phang}{stata "cre, abs(headroom): regress mpg price foreign" }{p_end}
{phang}{stata "cre, abs(foreign headroom): regress mpg price" }{p_end}
{phang}{stata "cre, compact abs(foreign headroom): regress mpg price" }{p_end}
{phang}{stata "cre, abs(headroom): regress mpg price foreign"}{p_end}
{phang}{stata "cre, abs(foreign headroom): regress mpg price"}{p_end}
{phang}{stata "cre, compact abs(foreign headroom): regress mpg price"}{p_end}

{phang}{stata "sysuse auto"}{p_end}
{phang}{stata "replace headroom=round(headroom)"}{p_end}
{phang}{stata "replace price=price/1000"}{p_end}

{pstd} For nonlinear models:{p_end}
{pstd}For nonlinear models:{p_end}
{phang}{stata "qreg mpg price foreign i.headroom, nolog q(10)"}{p_end}
{phang}{stata "cre, abs(headroom): qreg mpg price foreign , nolog q(10)" }{p_end}
{phang}{stata "cre, abs(headroom): qreg mpg price foreign, nolog q(10)"}{p_end}

{phang}{stata "logit foreign mpg price i.headroom"}{p_end}
{phang}{stata "cre, abs(headroom): logit foreign mpg price"}
{phang}{stata "logit foreign mpg price i.headroom"}{p_end}
{phang}{stata "cre, abs(headroom): logit foreign mpg price"}{p_end}

{marker Alsosee}{...}
{title:Also see}
Help: {help reghdfe}

Thanks
{phang}
Help: {help reghdfe}
Loading

0 comments on commit 4e102bb

Please sign in to comment.