maandag 25 februari 2013

Another tongue for BibLaTeX

This is a post in English, about getting LaTeX to speak Dutch. As such, it may be interesting for other rare languages.

In my last post I discussed the awkward natbib package. That was pretty bad. Now natbib is actually the old fashioned way of referencing. The advantage: it does the job for simple tasks. The disadvantage: everything else. So here's the hip new way of referencing: biblatex.

Yes, I'm being a cynic here. It's a big mess again. But for all of you who like a decent walkthrough, here you are.

Compiling BibTex

First of all, biblatex relies on the biber code, not bibtex. This means that you have to reset your editor to instruct biber where it asks for the bibtex path. Obvious? Not at all. I use TexMaker.
  • On a Windows machine: options > configure TM > commands > bibtex %
  • On the Mac: same, ending in > usr/texbin/bibtex % (or something like that. No .aux!)
Next, you'll need a sequens of parsing. I do this, repeating step 2 and 3 twice if it doesn't work the way I expected.
  1. pdflatex
  2. bibtex
  3. pdflatex
  4. view pdf
Note that you can define the parsing sequens as a user command in TexMaker/TexStudio.

Citing in line and bibliography

Ok, so let's turn back to your .tex file. You'll basically need this syntax in the preamble (before \begin{document}:

\usepackage[american]{babel}
\usepackage{csquotes}
\usepackage[style=apa, natbib=true]{biblatex}
\DeclareLanguageMapping{american}{american-apa}
%\addbibresource{/Users/username/folder/database.bib} %MAC
\addbibresource{D:/folder/database.bib} %PC
There's no need to specify backend=biber in the biblatex options, yet it does no harm. The standard style is numeric, an alternative is authoryear-comp, or you can follow some journal style, like the APA in this case. Because of the biblatex-apa call here, we need babel, csquotes and \DeclareLanguageMapping. You can change american for a language of your choice, such as dutch, german or french. Do this everywhere it appears in this block of syntax. Do not use multiple languages. This is a shame, as many non-English authors may want to quote in English. Well, you can't.


In the body of your text, after \begin{document} you use the biblatex commands \cite, \textcite and \parencite, or the old natbib commands \cite, \citet and \citep for reasons of compatibility or demands from the publisher. To make the latter work, I specified the option natbib=true. there are a number of other options, such as the suppression of urls and ISBN or DOI numbers, you may want to add.


Before \end{document}, you put \printbibliography. This generates a bibliography, with appropriate translation: 'october' (EN) becomes 'oktober' (NL) in datas, 'references' becomes 'referenties' as heading, etc.


It took me a full day to find this out. I hope you found this post quick enough to keep some time for the real work.

End note

If along the way you get stuck, three things you may want to do:
  • Update your editor and your packages. Use TexLive. It's a fat ugly program, but it's made to be updated (the program you need is texutility on OS X and tl-tray-menu on windows)
  • Restart your editor. Sometimes it remembers old lines for no reason.
  • Erase all latex files except the database (.bib), the text (.tex) and maybe the pdf to save your ass if you miss out on the first two.

vrijdag 22 februari 2013

BibTeX (natbib)

The much praised reference program BibTeX is an essential part of all academic LaTeX work. It took me some time to understand what it does. You should keep the following sequens in mind:
  • First you process an .aux file from you .tex text using LaTeX (i.e. compile > LaTeX)
  • That thing is full of code you need to parse through BibTeX to turn the reference fields into references (i.e. compile > BibTeX)
  • Doing each step twice may be a good idea to get cross references right
  • Next, you parse again using LaTeX
  • Finally, you parse the whole thing using pdfLaTeX, to get a pdf (it's a miracle...)
You will agree with me that this is a very cumbersome operation. It is one of the reasons I would recommend using Zotero with a word processor plugin, if you don't really need LaTeX.

But it gets worse. This is how you set up your .tex file.
  • In the preamble, so before \begin{document}, you need to load the BibTeX package. The old and safe way is \usepackage{natbib}. It seems there is a new and more flexible BibTeX connection called biblatex. So you heard it right: natbib won't let you make bibliographies for chapter, for example. Whence the praise, I wouldn't know.
  • Also in the preamble, although some write it elsewhere, you need to mention the bibliography style. It is \bibliographystyle{plainnat}. In some sciences, this is just plain, and for some journals this will be a specific style. You can't modify this, as the .sty files with the definition are very hard to decypher. LaTeX guys would say: 'Why would you?' Honestly, because I like simple languages. I use Stata instead of SAS, and that's why.
  • Obviously, in the standard format, you'll want your bibliography at the end. That's where you'll have it, just type \bibliography{library path}. Library path may be just the name of the library if it's in the same folder, but if you have a copy of your Zotero or Mendeley library at a fixed place, you should give the full path, and beware not to have spaces in it. Also, change backslash for slashes. Usability, you know?
Having gone through all that, you may want to start quoting. Luckily, that's the good part. You need not click any buttons, just type \cite{ and you have a list of labels to choose from. The handy thing is the AutoZotBib plugin for Zotero simply labels entries with the name of the first author, the first word of the title and the year. So it's pretty easy to call in your references. There's a few elegant options to quote:
  • \citep{ : this numbers references, if you like that. If you care less about names, do it wiki-style.
  • \citeauthor{ : obviously, you'll just get the author
  • \citeyear{ : well... you get it
So in sum, it's a pain in the ass, but it works.

One note: you may have weird characters in your references, like Swedish names. You know that LaTeX is English based so you may go down because of your Swedish friends. I haven't really figured out yet, I will in time, but maybe some fontpackage, such as \usepackage[T1]{fontenc}, may help you out. Good Lord, this ain't how it was meant to be.

Good luck referencing!


donderdag 14 februari 2013

Economische desinformatie in de pers

Veel opinie schrijf ik hier niet, maar vandaag doen we het toch. Ik blader even door De Morgen - online natuurlijk:

30 januari 2013: "Inflatie daalt sterk na aanpassing berekening"
Men vergelijkt waarschijnlijk de jaar-op-jaar consumptieprijsindex van januari en december. Dat soort dingen durft al eens flucturen, wat kan te wijten zijn aan de daling van december op januari dit jaar of een omgekeerde beweging vorig jaar. De meest waarschijnlijke verklaring van een terugval van het prijspeil is ... crisis, terugval van de vraag. De winterkoopjes zijn geen succes geweest, de spaarquote stijgt, Alexander De Croo is minister van pensioenen geworden, ... wat moet men nog meer hebben om te wanhopen?

Is het dan onmogelijk dat de 'methodologisch' wijzigingen aan de index een impact hebben gehad? Wat mij betreft, op dit moment: inderdaad. Lonen worden gebaseerd op basis van een drie maandelijks voortschrijdend gemiddelde van de 'sociale index' of gezondheidsindex. Soms zijn de maten nog exotischer. Die aanpassing gebeurt enkel bij het overschrijden van de spilindex (een verschil van 2 procent op de index ten opzichte van de vorige aanpassing), of op gezette tijdstippen. Dat is niet noodzakelijk januari. Maar zelfs dan kan de mindere indexering van de lonen pas een effect hebben op de prijzen in februari, want lonen worden meestal op het eind van de maand betaald. Tenzij men nu al denkt geld over te hebben. Het is allemaal eerder koffiedik kijken dan wetenschap.

7 februari 2013 "België hoog maar stabiel op 'Big Mac'-index"
Het tij is blijkbaar echt gekeerd, want Big Mac's worden niet duurder. Wel in Italië, en dat is nefast voor de export. Tja... Ik wist niet dat onze Big Mac's uit Italië kwamen. Enfin, lachen met de Italianen, ze vragen er ook om, maar dit is opnieuw meer infotainment dan iets anders.

14 februari "Lonen in België stegen 5,1 procent meer dan bij buren"
We gaan dat Technisch Verslag dan eens lezen, maar het gaat waarschijnlijk over de loonkost, en niet de lonen. Hoe dan ook is het eigenaardig, want de loonstijging zelf (gemeten met de ICL) is in België bij de laagste van Europa en zit serieus onder de productiviteitsstijging. Hoe komt het dan dat de loonkost sterker stijgt? Belastingen zijn één ding, maar compositie-effecten spelen ook een rol: als meer Belgen in een goede job terechtkomen - in vergelijking met het buitenland - dan zal ons relatieve loonpeil ook stijgen. Is dit een concurrentiehandicap? Niet noodzakelijk. Het kan zijn dat er veel lageloonjobs verdwijnen, maar dit kan niet het gevolg zijn van de loonevolutie want die is lager dan elders (enfin, Duitsland doet nog slechter). Er is dus een verandering van de economie, richting jobs voor hoger opgeleiden, en dat willen we toch?

maandag 11 februari 2013

Algoritme voor een longitudinale, representatieve steekproef

Nemen we twee types steekproeven:
  • Longitudinaal: steekproef in jaar t, eenheden opgevolgd door de tijd
  • Cross-sectioneel: steekproef in jaar t, steekproef in jaar t+1, t+2, ...
Men zou denken dat deze benaderingen onverzoenbaar zijn. Nochtans is er een algoritme dat toelaat steeds representatief te blijven, én over longitudinale gegevens te beschikken.

Dit voorbeeld kan toegepast worden op de selectie van werknemers, waar de populatie afhankelijk is van de werkloosheid.

Jaar t
Men neemt een steekproef, bijvoorbeeld 25% van de populatie.

Jaar t+1
Er is uitstroom uit de populatie. Dit is geen probleem: aangezien de steekproef aselect is verwachten we dat de sample een gelijke uitstroom heeft. We behouden eenvoudigweg de cases uit jaar t.
Er is ook instroom. Hieruit moeten we opnieuw 25% gaan selecteren.

Jaar t+2
Uitstroom en instroom zullen zich telkens herhalen zoals in jaar t+1.
Er is ook herinstroom in de populatie. Dit betekent voor onze steekproef dat we alle ooit geselecteerde eenheden moeten opvolgen, en opnieuw opnemen als ze terug in de populatie komen. Zij blijven namelijk altijd 25% van het gelijkaardig segment (de herinstroom) vertegenwoordigen. De steekproef blijft dus representatief.

dinsdag 5 februari 2013

Coding sectors based on NACE rev 1.1 and NACE rev. 2


Below is a broad categorisation of the NACE activities in four groups:

  1. Primary sector and construction
  2. Manufacturing and energy (including water, waste and recycling)
  3. Services and entertainment
  4. Public sector, education and health (including libraries)

The syntax below can be used in Stata straight away:

Based on NACE rev. 1.1

gene s_industryR1 = .
replace s_industryR1 = 1 if y10_nace_rev1 >= 1 & y10_nace_rev1 <= 14 // primary sector + construction
replace s_industryR1 = 1 if y10_nace_rev1 == 45 // primary sector + construction
replace s_industryR1 = 2 if y10_nace_rev1 >= 15 & y10_nace_rev1 <= 41 // manufacturing + energy ressources
replace s_industryR1 = 2 if y10_nace_rev1 == 90 // manufacturing + energy ressources
replace s_industryR1 = 3 if y10_nace_rev1 >= 50 & y10_nace_rev1 <= 74 // services + entertainment
replace s_industryR1 = 3 if y10_nace_rev1 >= 91 & y10_nace_rev1 <= 97 // services + entertainment
replace s_industryR1 = 4 if y10_nace_rev1 >= 75 & y10_nace_rev1 <= 85 // PEH
replace s_industryR1 = 4 if y10_nace_rev1 == 99 // PEH


Based on NACE rev. 2

gene s_industryR2 = .
replace s_industryR2 = 1 if y10_nace_rev2 >= 1 & y10_nace_rev2 <= 9 // primary sector + construction
replace s_industryR2 = 1 if y10_nace_rev2 >= 41 & y10_nace_rev2 <= 43 // primary sector + construction
replace s_industryR2 = 2 if y10_nace_rev2 >= 10 & y10_nace_rev2 <= 39 // manufacturing + energy ressources
replace s_industryR2 = 3 if y10_nace_rev2 >= 45 & y10_nace_rev2 <= 82 // services + entertainment
replace s_industryR2 = 3 if y10_nace_rev2 >= 92 & y10_nace_rev2 <= 98 // services + entertainment
replace s_industryR2 = 3 if y10_nace_rev2 == 90 // services + entertainment
replace s_industryR2 = 4 if y10_nace_rev2 >= 84 & y10_nace_rev2 <= 88 // PEH
replace s_industryR2 = 4 if y10_nace_rev2 == 91 // PEH
replace s_industryR2 = 4 if y10_nace_rev2 == 99 // PEH

Info on the box: http://www.quackit.com/html/codes/horizontal_scroll.cfm